Skip to content

sl-dialog stopPropagation of Escape #2142

Answered by KonnorRogers
mrbrahman asked this question in Help
Discussion options

You must be logged in to vote

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 sl-dialog isn't part of the composedPath.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@mrbrahman
Comment options

@KonnorRogers
Comment options

Answer selected by mrbrahman
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants