594
Views
9
Comments
Reactive popup close by esc key
Question

Would it be possible to close the reactive popup by pressing the esc key?

2020-01-08 12-23-57
Jitender Gaur

Hi Freek, 

There is no default option to close the reactive popup by pressing the esc key. You need to create event for the popup like Onkeypress or Onkeyup to trigger event. After that it will be possible to close popup by esc key..  

 

2020-03-01 17-52-33
Nikhil Gaur

Hi Freek,

You can add below script using JS block on onReady event of the screen

document.onkeydown = function(evt) {
    evt = evt || window.event;
    var isEscape = false;
    if ("key" in evt) {
        isEscape = (evt.key === "Escape" || evt.key === "Esc");
    } else {
        isEscape = (evt.keyCode === 27);
    }
    if (isEscape) {
        $actions.Hide();
    }
};

In the $Action.Hide client action just set the show pop variable to false.

UserImage.jpg
Saransh

Nice. Thanks for this.

2023-07-18 09-00-28
Prashant Raghuwanshi

its working

2025-11-24 16-53-49
Tiago Rodrigues
 
MVP

Hi freek!

That's a good question! I tried with the event OnKeyPress but I did not work.
The only solution that I can imagine by now is for you to build a JS script with a key listener that hides the popup. You will need to pass the Widget Id so that the JS code recognize the HTML object.

Hope it helps you.

Cheers

2020-03-01 17-52-33
Nikhil Gaur

Tiago Rodrigues wrote:

Hi freek!

That's a good question! I tried with the event OnKeyPress but I did not work.
The only solution that I can imagine by now is for you to build a JS script with a key listener that hides the popup. You will need to pass the Widget Id so that the JS code recognize the HTML object.

Hope it helps you.

Cheers

HIi Tiago,

Yes, you are right. A key listener is needed but there is no need to pass the widget id and setting widget's style for hiding it. It will break its relation with the boolean variable we are using originaly to show/ hide the popup.

From the javascript we can simply call a screen client action which sets the boolean variable to false and popup will close automatically based on this boolean value.


UserImage.jpg
pramod jain

document.addEventListener('keydown', function(event){
if(event.key === "Escape"){
if($parameters.increment===1){
$actions.PopupClose()
}
}
});


In the $Action.PopupClose client action just set the show pop variable to false.

2022-07-11 07-38-06
Askeladd

Hi, is there any possible way to close the popup dialog by clicking outside the popup dialog/popup dialog container?

pop.png
UserImage.jpg
freek

havent test it but something like this maybe?

// Add a click event listener to the document to listen for clicks

document.addEventListener('click', function(event) {

    // Check if the clicked element is not inside the popup

    var popup = document.querySelector('.popup'); // Replace '.popup' with the correct selector for your popup


    if (!popup.contains(event.target)) {

        // Click was outside the popup, close the popup

        $actions.PopupClose(); // Call your function here to close the popup

    }

});


// Add a keydown event listener for the Escape key

document.addEventListener('keydown', function(event) {

    if (event.key === "Escape" && $parameters.increment === 1) {

        $actions.PopupClose(); // Call your function here to close the popup

    }

});


Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.