Skip to main content
PimentCSS v1.0.1, what's new
Home

Modals

Modal overlay, focus trap, and action footers.

Blocking modal dialogs for focused tasks, forms, and multi-step flows. Styles live in scss/components/_modal.scss. For destructive confirmations with limited choices, use alert dialog on the Alerts page. For layout blocks in the page, see Cards.

Overlay with role="dialog", aria-modal="true", labelled title, optional description, scrollable body, and footer actions. The root stays in the DOM with hidden when closed.

Modal vs alert dialog

  • Modal (.modal), general content and forms. Backdrop dismiss is optional (data-modal-static).
  • Alert dialog (.alert-dialog), urgent decisions with limited actions. See Alerts.

Default width uses $modal-max-width (32rem). Add modal--sm (24rem) or modal--lg (42rem) on the root. Set data-modal-static on the root to require an explicit close (no backdrop dismiss) for forms or drafts.

Open with data-modal-open="{id}", close with data-modal-close or backdrop data-modal-dismiss. Copy docs-site/src/lib/modal-behavior.ts for focus trap, Escape, scroll lock, and focus restore.

Class reference

Class / attributeDescription
.modalFixed overlay root (hidden when closed)
.modal__panelDialog surface (role="dialog")
.modal__header / .modal__body / .modal__footerRegions (title, scrollable content, actions)
.modal--sm / .modal--lgWidth presets
data-modal-openOpens modal by id
data-modal-closeCloses modal
data-modal-dismissBackdrop click closes (omit with data-modal-static)
data-modal-liveWires reference behavior script

Customize (Sass)

  1. Override modal tokens before importing components.
    @use "pimentcss-design-system" with (
      $modal-max-width: 36rem,
      $modal-max-width-lg: 48rem,
      $modal-z: 1300
    );
  2. Run after editing _modal.scss.
    npm run build:css

Accessibility (RGAA / WCAG)

Modals

  • Role, use role="dialog" (not alertdialog) for general tasks. Reserve alertdialog for urgent, limited-choice prompts.
  • Naming, aria-labelledby points to the visible title; add aria-describedby when extra context is needed.
  • Focus, move focus into the panel on open, trap Tab inside, restore focus to the trigger on close. Escape closes unless data-modal-no-escape.
  • Scroll, lock page scroll (body.modal-open) while open; keep long content in .modal__body.

Next steps