<u-dialog>
There is no longer need for <u-dialog> 🎉
Please use native <dialog> as it has sufficient support
in major browsers and screen readers.
Quick intro:
- Use
<dialog>to create a modal or non-modal dialog box - Use
openattribute to set open state - MDN Web Docs: <dialog> (HTMLDialogElement)
Example
<button type="button" onclick="this.nextElementSibling.showModal()">
Open dialog
</button>
<dialog>
<p>Greetings, one and all!</p>
<form method="dialog">
<button>OK</button>
</form>
</dialog>
Install
Nothing to install 🎉
Attributes
<dialog>
- Attributes: all global HTML attributes such as
id,class,data-openshows dialog. By default this attribute is absent which means the dialog is hidden. Note:openmakes the dialog non-modal, so is instead recommended to use the.show()or.showModal()for greater control.
- DOM interface:
HTMLDialogElementHTMLDialogElement.openreturnstrueoffalsereflecting the stateHTMLDialogElement.returnValuestring reflecting the return value for the dialogHTMLDialogElement.show()opens as non-modal, allowing interaction outsideHTMLDialogElement.showModal()opens as modal, preventing interaction outsideHTMLDialogElement.close()closes the dialog
Accessibility
Note that older versions of Firefox may erroneously permit the screen reader focus to move out of the <dialog> element. However, this does not justify the creation of a <u-dialog>, as screen reader focus isn't detectable via JavaScript and thus cannot be controlled or prevented through JavaScript either.
Specifications
- DOM interface: HTMLDialogElement
- HTML Standard: The <dialog> element