Modal
The dialog
is a version of a popup window that does disable interaction
with the rest of the page.
To open the modal, do not use the open
attribute. Instead, open
it using JavaScript via dialogElement.showModal()
function. This way, the esc functionality is
enabled by default (no JS needed).
In the example below, you can see a form
as the wrapper of the article. This way,
the modal will be auto-closed by a submit button. If you want to close a modal without
submitting the form, you need to add formmethod="dialog"
to the submit button as shown
below.
<dialog>
<form>
<article role="presentation">
<header>
<h3>Modal title</h3>
<button
type="submit"
formmethod="dialog"
aria-label="Close" >
</button>
</header>
Lorem ipsum dolor sit, amet consectetur adipisicing elit.
Asperiores vitae officia, voluptatem modi quos quisquam
similique tenetur voluptatum, ratione suscipit numquam dolore
aperiam molestiae impedit. Ut, maiores? Alias, quos facilis.
<footer>
<div class="s-grid" style="--span:3;">
<div>
<div>
<button
formmethod="dialog"
class="s-secondary"
type="submit">
Cancel
</button>
</div>
<div><button type="submit">Submit</button></div>
</div>
</div>
</footer>
</article>
</form>
</dialog>