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.
<dialog closedby> isn't supported here. Chrome 133+ required.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.