Behaviors
Dialog behavior
Focus restore, backdrop click, and deep links on top of the native dialog.
Usage#
import { initDialogs, openDialog, closeDialog } from '@originlabsbr/halora/dialog';
const stop = initDialogs({ hash: true }); // data-ha-dialog-open / close, backdrop, hash| Name | Signature | Description |
|---|---|---|
initDialogs | ({ root?, selector?, hash? }) => destroy | Wire all dialogs under root. With hash true, #id opens a dialog on load and on hashchange. |
openDialog | (dialog, { trigger?, hash? }) => void | Call showModal, or set the open attribute without it. Remembers the trigger. |
closeDialog | (dialog, { hash? }) => void | Close. The close event restores focus and clears the hash. |
isBackdropClick | (event, dialog) => boolean | True when the click targets the dialog and lands outside its box. |
idFromHash | (hash) => string | "#cv" to "cv". |
Backdrop detection compares the click position with the dialog rectangle, so a click on empty space inside the dialog does not close it. Escape is handled by the browser.
See the Dialog component for markup.