demo · v133

Escape, backdrop, and the cancel event

Different closedby values surface different events. closerequest still fires cancel (which you can preventDefault); any tries cancel on Escape but the backdrop click closes silently. Try the three pickers below and watch the event log.

Confirm subscription

Press Esc or click the dim backdrop to attempt dismissal. The page logs which event ran and whether it was cancellable.

open the dialog and try Escape, backdrop click, and the buttons.

which events fire

gesture none closerequest any
Escape no event cancel + close cancel + close
backdrop click no event no event close (silent)
form submit close (with returnValue) close close

When cancel fires you can preventDefault() to keep the dialog open — the same hook as before, just now controlled by the declarative attribute.

see also