--- title: Dialog description: Use Dialog to present modal dialogs with customizable sizes, animations, and focus management. --- The Dialog component relies heavily on [The HTMLDialogElement interface](https://developer.mozilla.org/en-US/docs/Web/API/HTMLDialogElement). The component must be initialized from Javascript. In the Envision scripted component you will find a few extra features: - Opener button added as option on initialization - Close on click outside as an option - Nice fade-in animation - Focus trap to keep tab navigation from leaving the dialog ## Default dialog
The alertdialog role is to be used on modal alert dialogs that interrupt a user's workflow to communicate an important message and require a response.To make a Dialog an alertdialog, add `role="alertdialog"`, and make sure to use an accessible name and description for example by adding attributes `aria-labelledby` and `aria-describedby`. **Note**: The option `backdropClick` will automatically be set to `false` for alertdialogs and cannot be overridden. Keypress `Escape` will not close the dialog. Available alertdialog variations: `env-dialog--'error', 'success', 'warning', 'info'` ```html ``` ## Options ```javascript // Default options { opener: null, backdropClick: true, placement: null, } ``` - `opener` _'string'_ | _Node_ - A selector as a string or a DOM Node to assign event listener for opening the dialog. - Default value: `null` - `backdropClick` _boolean_ - Click on backdrop (outside dialog) should close the dialog (not available for alertdialog). - Default value: `true` - `placement` _'string'_ - Dialog window should be moved in the DOM and open as an immediate child of ``. - Allowed values: `'body'` - Default value: `null` ## API Instances of Dialog may be controlled by the methods described below. ```javascript envision.dialog('#dialog', { opener: '#opener' }).then(function (dialogs) { console.log(dialogs[0].el.open); // dialogs[0].show(); // Uncomment to show dialog on load }); ``` ```javascript envision.dialog('#dialog').then(function (dialogs) { // Custom opener event document.querySelector('#opener').addEventListener('click', () => { // ... before show ... dialogs[0].show(); }); }); ``` ### Options - `el` - Access to the [HTMLDialogElement interface](https://developer.mozilla.org/en-US/docs/Web/API/HTMLDialogElement), e.g. `open` and `returnValue`. - `show()` - Show the dialog. Uses [HTMLDialogElement showModal()](https://developer.mozilla.org/en-US/docs/Web/API/HTMLDialogElement/showModal) to always display the dialog in the [top layer](https://developer.mozilla.org/en-US/docs/Glossary/Top_layer). - `close()` - Close the dialog. ## Events Use [native HTMLDialogElement events](https://developer.mozilla.org/en-US/docs/Web/API/HTMLDialogElement#events). ### Example ```javascript envision .dialog(document.querySelector('#dialog'), { opener: '#opener', }) .then((dialogs) => { dialogs[0].el.addEventListener('close', () => { // ... do something when dialog is closed console.log(dialogs[0].el.returnValue); }); }); ``` ## Legacy documentation Dialog is a replacement for the deprecated [Modal Dialog](/deprecated/modal-dialog/).