Skip to content

Modal ​

A dialog over a dimmed page, for a task or a decision that needs full attention.

modals-basemodal--defaultOpen in Storybook ↗

When to use ​

  • Creating or picking something without leaving the page: a form, a picker.
  • Confirming an action that cannot be undone, or leaving a form with unsaved changes. Use the confirm dialog.
  • A delete that must first show which related records go with it.

When not to use ​

  • Editing a single field: edit it in place, with a text input or another field control.
  • Help or hints: use a tooltip or the info panel.
  • Choosing an action: use an overflow menu.
  • A wait without a decision: show loading in the region itself.

Anatomy ​

  1. Scrim: --color-scrim over the page behind.
  2. Container: --shadow-modal; centred dialogs have --radius-overlay corners. Below 48rem the dialog fills the screen, without corners.
  3. Header: the panel-header band (--panel-header-pad) with the title in bold --text-panel-title, optional extra controls, and a close button (✕) at the end. On small screens the close button is --touch-target-min square. Without a title the header holds only the close button.
  4. Body: the task itself, such as a form with its own action button at the end. It scrolls when its content is taller than the dialog. The modal adds no buttons of its own.
  5. Footer (confirm dialog): a top border, --modal-footer-pad, buttons aligned right. The message above it uses --modal-body-pad.

Variants ​

VariantShapeWhere
Centredcentred, height cappedforms, pickers, the confirm dialog
Centred widecentred, wider and tallerlarge pickers, the delete dialog
Side panelfull height, against the right edgeforms and pickers that sit beside the page
Side panel widethe same, widersaved searches, media
Confirm dialogcentred, title, message and buttonsdecisions
Inline confirma button pair inside a dialog's contentthe end of the delete dialog

Confirm dialog. A title, an optional message and up to three buttons, from left to right: Cancel (ghost), an optional second choice and the confirm action (both danger by default). The second choice offers a way out that is not cancelling, such as Save changes and leave editor in the commit colour. Asking a new question while one is open cancels the first.

base-confirmmodal--defaultOpen in Storybook ↗

Inline confirm. A confirm button (danger) and a cancel button (secondary) side by side, sharing the width, in the small size. The delete dialog ends with it, under any related records that are deleted along with the record.

base-inlineconfirmbuttons--defaultOpen in Storybook ↗

States ​

StateWhat you seeTrigger
Openscrim and dialog; the page behind cannot be reached or scrolledan action opens it
Busya translucent layer with a spinner and a message covers the dialoga long operation runs
Asking to leavea confirm dialog on top: Leave formclosing a form with unsaved changes
Confirming (inline)spinner in the confirm button; cancel is disabledthe delete runs
Closeddialog and scrim disappearclose button, Escape, a cancel button, or the task completes
modals-basemodal--busyOpen in Storybook ↗

A click on the scrim does not close the dialog.

Keyboard & accessibility ​

KeyEffect
Tab / Shift+Tabmoves between the controls of the dialog only
Escapecloses the dialog; in a confirm dialog it counts as Cancel
Enter / Spaceruns the focused button
  • It is a native modal <dialog>: the page behind is inert while it is open.
  • The title names the dialog (aria-labelledby). Always give a title; without one the dialog has no name.
  • The close button is named Close.
  • On open, focus goes to the first focusable element, which is the close button. A confirm dialog moves focus to Cancel, so Enter never confirms a destructive action by accident.
  • Closing a confirm dialog with ✕ or Escape counts as Cancel.
  • A confirming inline button is aria-busy="true"; see Button.

Content ​

  • The title says the action or asks the question: Delete permanently?, Leave form.
  • The message says what happens: You're deleting 'Annual report' (Asset) permanently. This can't be undone.
  • Buttons name the action with a verb: Delete permanently, Leave editor. Never OK or Yes.
  • The cancel button is Cancel.

Button · Loading · Tooltip · Accessibility

Powered by Elody - Open Source Semantic Data Platform