sl-dialog stopPropagation of Escape #2142
-
Hi, The default behavior of sl-dialog Escape closes the dialog, which is good. However, after the close, I would like to stop propagating the Esc press, as there are other elements listening to Escape as well. How can I achieve this? Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
You should be able to do this using by adding a direct listener onto the dialog and stopping the propagation yourself. Something like this: dialog.addEventListener("keydown", (e) => {
if (e.key === "Escape" && dialog.open) {
e.stopImmediatePropagation()
dialog.hide()
}
}) https://codepen.io/paramagicdev/pen/oNrEdeJ?editors=1000 The other option if you control the other event listeners is adding composedPath checks that make sure |
Beta Was this translation helpful? Give feedback.
You should be able to do this using by adding a direct listener onto the dialog and stopping the propagation yourself.
Something like this:
https://codepen.io/paramagicdev/pen/oNrEdeJ?editors=1000
The other option if you control the other event listeners is adding composedPath checks that make sure
sl-dialog
isn't part of the composedPath.