Dialog component.
Features:
- Best accessibility practices baked in
- Tab and focus lock on tabbable elements inside dialog
- Handles usual UX considerations such as closing on Escape key and clicking on dialog backdrop
- Flexible styling
- Sets
aria-hiddenon all sibling and ancestor elements except for the currently active dialog which traps the virtual cursor inside the dialog
npm install @statua/dialog --saveimport dialog from '@statua/dialog';
const instance = dialog({
content: `<p>Becky</p>`
});
instance.show();Returns: Object
Creates dialog instance. Dialog element will be appended to body element.
Type: Object
Type: string|Node
Required
Dialog content which can be:
- HTML string
- Instance of
Node(DOM node, HTML comment, document fragment, …)
Type: Function
Default: () => {}
Callback to run when dialog instance is created.
Type: Function
Default: () => {}
Callback to run when dialog instance is destroyed.
Useful when you want to perform operations such as moving dialog content to original location if dialog content was already existing DOM node.
Type: Function
Default: () => {}
Callback to run when dialog instance is shown.
Type: Function
Default: () => {}
Callback to run when dialog instance is closed.
Type: string
Default: ``
HTML class namespace in addition to default one (statua-Dialog).
Useful if you want to create additional styling/functionality selector hook.
Type: boolean
Default: false
Disable modal close on Escape key press or when modal backdrop is clicked.
Show dialog.
Close dialog.
Destroy dialog instance.
Dialog instance can be controlled with certain DOM attributes.
Closes closest dialog instance when clicking on element.
Tested in IE11+ and all modern browsers.
For automated tests, run npm run test:automated (append :watch for watcher
support).
MIT © Ivan Nikolić