Shells
Modal
A real <dialog>. Focus trapping, Esc-to-close, inertness and the top layer come from the browser rather than from a script this language does not ship.
Open it with el.showModal(), not by setting the open attribute.
Only showModal() promotes the dialog to the top layer, makes the rest of the
page inert and draws the backdrop; the bare attribute renders it inline with
none of that, which is what the examples below do so they can sit in the page.
The examples' style="position: static; margin: 0" exists only so the demo
sits inline in the page - remove it when you open the dialog with
showModal(). The UA's dialog:modal rule sets position: fixed and the
base dialog rule sets margin: auto to centre it, and both are UA-origin
styles that lose to an inline author declaration; leave the inline style in
place and a dialog you open with showModal() still gets the top layer and
the backdrop, but is laid out in normal flow instead of centred over it -
typically pinned to the bottom-left of the document. .axi-drawer documents
the identical override for the same reason.
A <dialog> brings its own ::backdrop, so the modal styles that rather than
reusing .axi-scrim. They look identical and are not the same element - the
alternative was giving up <dialog> and hand-rolling a focus trap.
The head and foot are divided from the body by rules rather than outlines: they are parts of one raised thing.
The surface is --axi-surface-float. A modal is the strongest case that
token has: the entire app is behind it, and a scrim does not rescue a
.42-alpha pane on a platform where the blur is unavailable.
If you already own an overlay stack, put .axi-modal on a <div> and
.axi-scrim on the element behind it. The surface, the weight and the block
are all in the class and none of them want a <dialog>; ::backdrop simply
never matches, which is why the scrim is a separate element here rather than a
pseudo. What you give up is the paragraph above - the focus trap, the
inertness, Esc, the top layer - and that is a real cost, not a formality. Take
this path when the app already has the z-index order and the trap, not to
avoid showModal().
Give the heading an id and point the dialog's aria-labelledby at it, or
the dialog announces with no name at all.
A confirmation
Shown inline with the open attribute so it sits in the page; a real one is opened with showModal() and draws a backdrop over everything. Remove position: static and margin: 0 when you do - they exist only to hold the demo in the page<dialog class="axi-modal" open aria-labelledby="modal-confirm-title" style="position: static; margin: 0">
<div class="axi-modal__head">
<span class="axi-diamond axi-diamond--danger"></span>
<h2 id="modal-confirm-title">Delete this log?</h2>
</div>
<div class="axi-modal__body">This removes the parsed encounter and its shareable link. The file on disk is untouched.</div>
<div class="axi-modal__foot">
<button class="axi-btn axi-btn--ghost">Cancel</button>
<button class="axi-btn axi-btn--primary">Delete</button>
</div>
</dialog>
A wider one, with a form in it
The width knob is clamped against the viewport, so a wide modal still fits a narrow window. Remove position: static and margin: 0 when opening it with showModal() - they exist only to hold the demo in the page<dialog class="axi-modal" open aria-labelledby="modal-upload-title" style="position: static; margin: 0; --axi-modal-width: 680px">
<div class="axi-modal__head"><h2 id="modal-upload-title">Upload settings</h2></div>
<div class="axi-modal__body">
<label class="axi-row"><input type="checkbox" class="axi-check" checked> Parse on upload</label>
<label class="axi-row"><input type="checkbox" class="axi-check"> Make the link public</label>
</div>
<div class="axi-modal__foot"><button class="axi-btn axi-btn--primary">Save</button></div>
</dialog>
Knobs
| Property | Sets | Fallback |
|---|---|---|
--axi-modal-width | the maximum width of an .axi-modal, before the viewport clamp | 560px |