Skip to main content
U.S. Flag

An official website of the United States government

Modal Dialog

The dialog component can be used to focus a user's attention on a single piece of content, without taking them to a new screen. Please use with caution; view our guidance for more details.

Examples

Loading

Dialog size variants

Apply one of the size modifier classes to the ds-c-dialog element to change the dialog width.

  • .ds-c-dialog--narrow
  • .ds-c-dialog--wide
  • .ds-c-dialog--full

Code

React

React Properties Documentation
NameTypeDefaultDescription
analyticsbooleantrue

Analytics events tracking is enabled by default. Set this value to false to disable tracking for this component instance.

analyticsLabelOverridestringHeading Content

An override for the dynamic content sent to analytics services. By default this content comes from the heading. \n In cases where this component’s heading may contain sensitive information, use this prop to override what is sent to analytics.

analyticsEventTypeOverridestring

If you need the event_type to be overridden for your use case, you can provide an alternate string here. Suggested values can be found in the EventType enum.

onAnalyticsEvent(event: AnalyticsEvent) => any

Optional callback that will intercept analytics events for this component. If none is specified, the design system will use the default analytics function, which can be overwritten globally with setDefaultAnalyticsFunction.

actionsReact.ReactNode

Buttons or other HTML to be rendered in the "actions" bar at the bottom of the dialog.

actionsClassNamestring

Additional classes to be added to the actions container.

alertboolean

If true, the modal will receive a role of alertdialog, instead of its default dialog. The alertdialog role should only be used when an alert, error, or warning occurs.

ariaCloseLabelstring

Aria label for the close button

backdropClickExitsboolean

Pass true to have the dialog close when its backdrop pseudo-element is clicked

childrenReact.ReactNode
classNamestring

Additional classes to be added to the root dialog element.

closeButtonSize'small' | 'big'

Size of the close button. See Button component

closeButtonTextReact.ReactNode

For internationalization purposes, the text for the "Close" button must be passed in as a prop.

closeButtonVariationButtonVariation'ghost'

Variation string to be applied to close button component. See Button component

closeIconReact.ReactNode<CloseIcon />

The icon to display as part of the close button

headerClassNamestring

Additional classes to be added to the header, which wraps the heading and close button.

headingReact.ReactNode

The Dialog's heading, to be rendered in the header alongside the close button.

idstring

A custom id attribute for the dialog element

size'narrow' | 'wide' | 'full'

The Dialog's size parameter.

Styles

The following Sass variables can be overridden to customize Dialog components:

Sass variables for dialog
VariableDefault Core Theme Value
$dialog__background-color$color-white
$dialog__padding32px
$dialog-overlay__background-color$color-transparent-black-alpha50

Google Analytics

Analytics event tracking is disabled by default.

Enable event tracking

Import and set the setDialogSendsAnalytics feature flag to true in your application's entry file:

import { setDialogSendsAnalytics } from '@cmsgov/<design-system-package>';
setDialogSendsAnalytics(true);

On applications where the page has utag loaded, the data goes to Tealium which allows it to route to Google Analytics or the currently approved data analytics tools.

Disable event tracking

For the analytics prop, pass the value false to the component to disable analytics tracking for a singular component instance

analytics={false}

Override event tracking

A custom heading value can be sent for an analytics event by using the prop analyticsLabelOverride. It is recommended that this value be used to prevent sensitive personal information from being passed to analytics trackers.

Guidance

Accessibility

Keyboard support

  • Enter or Space to select the highlighted item.
  • Tab to move the focus sequentially through the list of focusable items.
  • Shift + Tab to move the focus sequentially through the list of focusable items in reversed order.

Focus Management

  • When the modal is opened, the entire modal is the default focus state. Most screen readers will announce the entire dialog content.
  • Focus is trapped within the modal and users can then navigate through the dialog actions with the keyboard.
  • Escape will close the modal. To disable exiting when users press the Escape key, set the escapeExits prop to false
  • When the modal closes, focus returns to the element that was focused just before the modal is activated
  • To place the focus inside of the dialog on activating the modal, set the dialog focus using the initialFocus prop with boolean prop focusDialog set to false

Learn more

Component maturity

For more information about how we tested and validated our work for each checklist item, read our component maturity documentation.

Accessibility

  • Color

    Meets AA color contrast standards for accessibility and color blindness.
    Complete
  • Forced Colors Mode (FCM)

    While using FCM the components text is legible and improves readability.
    Complete
  • WCAG 2.1 Level AA Conformance

    All Axe checks for WCAG AA compliance have passed.
    Complete
  • Screen readers

    VoiceOver, NVDA, and JAWS screen readers provide concise communication and interaction.
    Complete
  • Keyboard navigation

    Component is fully navigable with a keyboard.
    Complete

Code

  • Storybook

    Component has stories to cover all defined props.
    Complete
  • Responsive

    Component designed to work in all responsive breakpoints.
    Complete
  • Spanish translations

    Includes Spanish translations for default text content.
    Complete

Tokens

  • Code

    Tokens implemented in code.
    Complete
  • Design

    Tokens implemented in the Sketch.
    Complete