Skip to content
Fleetline

Modal

Usage

Use a modal when the dispatcher must finish or cancel a short task before going on: reassign a mechanic, edit a service interval, confirm a deletion. The rest of the page becomes inert until it closes.

Content: the title states the task or the consequence as a question ("Reassign work order WO-1042", "Delete work order WO-1042?"). Buttons are verb + object ("Delete work order", "Reassign mechanic"); the dismiss action is "Cancel", never "No" or "OK". Put the primary action at the inline end with Cancel beside it.

Anatomy

  1. Backdrop — ::backdrop with --color-bg-overlay
  2. Container — <dialog class="modal"> on the overlay surface, --overlay-radius and --overlay-shadow
  3. Header — .modal__header: title .modal__title (an h2) and close button .modal__close; alert dialogs show a tone icon .modal__icon instead of the close button
  4. Body — .modal__body, the only part that scrolls
  5. Footer — .modal__footer: Cancel, then the primary action at the inline end

Examples

Open dialogs are previewed in the page with the docs-only .is-preview class; every demo also has a real trigger that opens the dialog in the top layer with commandfor/command="show-modal", without JavaScript.

Alert dialog

<button type="button" class="btn btn--destructive" commandfor="dlg-delete" command="show-modal">Delete work order</button>

<dialog id="dlg-delete" class="modal modal--alert modal--danger" role="alertdialog"
        aria-labelledby="delete-title" aria-describedby="delete-desc">
  <div class="modal__header">
    <span class="modal__icon" aria-hidden="true"><svg focusable="false"><use href="#icon-trash"></use></svg></span>
    <h2 class="modal__title" id="delete-title">Delete work order WO-1042?</h2>
  </div>
  <div class="modal__body"><p id="delete-desc">… This can't be undone.</p></div>
  <div class="modal__footer">
    <button type="button" class="btn btn--ghost" commandfor="dlg-delete" command="close" autofocus>Cancel</button>
    <button type="submit" class="btn btn--destructive" form="delete-wo-1042">Delete work order</button>
  </div>
</dialog>

API

HookValuesPurpose
<dialog class="modal">blockModal surface; open with command="show-modal"
.modal--sm | --lgmodifierWidth 30rem / 48rem (md 40rem default), always within the viewport
.modal--scrollmodifierAdds separators above and below a long scrolling body
.modal--fullscreen-mobilemodifierFills the screen below 40rem, stacks footer actions
.modal--alert + .modal--danger | --warningmodifierAlert dialog layout and icon tone; pair with role="alertdialog"
.modal__header | __title | __close | __icon | __body | __footerpartsSee anatomy
commandfor="id" command="show-modal | close"invoker attributesOpen and close without JavaScript
closedby="any"attributeLight dismiss (backdrop click) for non-destructive, non-form dialogs only; enhancement
autofocusattributeInitial focus target; on alert dialogs put it on Cancel
.is-preview | .is-mobiledocs-only classRender an open dialog in the page flow / force the mobile layout

Do and don't

Do name the action and the object, and focus Cancel first in destructive confirmations.
Don't ask "Are you sure?" with Yes/No or OK: people click through without reading.

Accessibility

Keyboard interaction
KeyBehavior
Tab / Shift+TabMoves between focusable elements inside the dialog; the page behind is inert
EscCloses the dialog (on an alert dialog it equals Cancel)
Enter / SpaceActivates the focused button

Tokens

Custom propertyPurpose
--color-elevation-surface-overlayDialog surface
--overlay-radius, --overlay-shadowCorner radius and elevation
--color-bg-overlayBackdrop scrim
--size-container-sm | -mdWidths (sm = 0.75 × container-sm)
--color-feedback-{danger|warning|info}-{bg|icon}Alert dialog icon tone
--typography-h4-*Title
--motion-duration-base | -fast, --motion-easing-enter | -exitEnter and exit
--size-touch-targetFull-width footer buttons on mobile