I have multiple dialogs / modals in my application. A couple of the are on the same page, accessible at the same time.
I use the DialogComponent
as a wrapper to set up the dialog stimulus controller.
Besides other actions which are not yet implemented, I want to close the dialog by clicking a button and by pressing ESC.
Therefor I defined two actions click->dialog#close
and keydown.enter->dialog#close
.
The dialog closes when clicking on the supposed close button but pressing ESC key does not do anything.
Why does pressing ESC not work? Do I need to assign the action on another element?
Using keydown.enter@document->dialog#close
appends the event listener to the document. The problem was that with @document
the eventlistener is just bound to the button and doesn't work as expected.