v131 · dom
Dialog Toggle Events
It is useful for web authors do determine when their <dialog> elements open and close. popover already has `ToggleEvent` which is dispatched when a popover opens or closes, but <dialog> does not. The current way to detect when a <dialog> opens is to register a mutation observer to check for open, however, this is quite a lot of work where an event would be e
concepts
-
Dialog ToggleEvent
<dialog> fires toggle events like <details>.
-
Nested dialog stack
Use the new
toggleevents to track an open-dialog stack across nested modals without mutation observers. -
Animation hook + @starting-style
Pair
beforetogglewith@starting-styleandallow-discreteto animate the dialog in and out fully declaratively. Speed slider live-tunes the transition duration. -
Cancel a close with a dirty guard
requestClose()firescancelbefore the dialog closes. Pair that cancellable event with a dirty-form flag to ship the canonical "are you sure?" confirmation prompt. -
History-Aware Dialog
Use the
toggleevent to mirror dialog open/closed state tolocation.hashviahistory.pushState(). The Back button closes the dialog; sharing the hashed URL re-opens it on load. No router library needed. -
beforetoggle Interceptor
A multi-step wizard that routes close attempts through
requestClose()andcancel, then usesbeforetoggleto log the final close transition.
why it shipped
It is useful for web authors do determine when their <dialog> elements open and close. popover already has `ToggleEvent` which is dispatched when a popover opens or closes, but <dialog> does not. The current way to detect when a <dialog> opens is to register a mutation observer to check for open, however, this is quite a lot of work where an event would be e