v139 · dom
'request-close' Invoker Command
Dialog elements can be closed through a variety of mechanisms, sometimes developers want to have the ability to prevent closure. To achieve this dialogs fire a cancel event. Originally this was only fired via a close request (e.g. ESC key press), recently a `requestClose()` JS function was added which also fires the cancel event. The '
concepts
-
Dialog Cancel Button
Click the cancel button to fire the dialog's cancel event before closing. Replaces the dialog.close() + cancel-event-dispatch dance with a single declarative command.
-
Form Guard
A form with unsaved changes uses the cancel event to
preventDefault()and keep the dialog open. Demonstrates thatrequest-closerespects the same intercept hook as the ESC key. -
Declarative Confirm Flow
An editor dialog with two buttons: declarative
request-closefor Cancel (guarded by a dirty-form check) andclosefor Save. Live event log shows the cancel ↔ close ordering. -
Nested Dialogs
Three dialogs — info, form, and a guarded delete dialog — each wired with
command="request-close". The delete dialog interceptscanceland opens a guard; an event log shows everycancelandcloseevent fired.
why it shipped
Invoker commands exposes existing dialog and popover functions to declarative HTML, for consistency we should also expose the new requestClose().