Skip to main content
U.S. Flag

An official website of the United States government

Drawer & Help Drawer

A drawer provides a space for medium to long-form help content — content that's too long or not common enough to warrant being on the page by default.

On large screens it's fixed to the side of the screen, and on smaller screens it overlays the entire screen.

Render the drawer below the toggle button that triggers it. This way the markup remains semantically sound and screen reader friendly.

Examples

Loading

Layout Alternatives

A header and/or footer can have a "sticky" position if the following properties are applied to their respective elements:

  • isHeaderSticky
  • isFooterSticky
Loading

Code

React

React Properties Documentation
NameTypeDefaultDescription
ariaLabelstring

Gives more context to screen readers on the Drawer close button.

closeButtonTextReact.ReactNode
childrenrequiredReact.ReactNode
classNamestring
footerBodyReact.ReactNode
footerTitlestring
hasFocusTrapbooleanfalse

Enables focus trap functionality within Drawer.

headingrequiredstring | React.ReactNode

Text for the Drawer heading. Required because the heading will be focused on mount.

headingIdstring

A unique id to be used on heading element to label multiple instances of Drawer.

headingLevel'1' | '2' | '3' | '4' | '5''3'

Heading type to override default <h3>

headingRefReact.MutableRefObject<any>

Ref to heading element

isHeaderStickyboolean

Enables "sticky" position of Drawer header element.

isFooterStickyboolean

Enables "sticky" position of Drawer footer element.

onCloseClickrequired(event: React.MouseEvent | React.KeyboardEvent) => void

<DrawerToggle>

React Properties Documentation
NameTypeDefaultDescription
drawerOpenrequiredboolean

Determines if Drawer is open or closed. This value is used to re-focus the toggle that opened the drawer when the drawer closes.

childrenrequiredReact.ReactNode

DrawerToggle content.

classNamestring

Additional classes for the toggle button anchor element.

inlineboolean

Adds display: inline to the DrawerToggle.

showDrawerrequired(string) => any

This function is called with an id that the toggle generates. It can be used in implementing the Drawer for keeping track of which drawer the toggle controls.

<HelpDrawer>

This component is an enhanced <Drawer> component, providing the same properties as <Drawer> in addition to Google Analytics properties.

React Properties Documentation
NameTypeDefaultDescription

Focus Trap

A focus trap can be set on a drawer if the property hasFocusTrap is enabled. A user can escape the focus trap by pressing the ESC key.

Styles

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

Sass variables for drawer
VariableDefault Core Theme Value
$drawer__animation-timing0.3s
$drawer__background-color$color-white
$drawer__border-color$color-border
$drawer-close__color$color-black
$drawer-header__background-color$color-gray-lightest
$drawer-footer__background-color$color-primary-alt-lightest
$drawer-toggle__background-color--hover$color-focus-inverse
$drawer-toggle__color--hover$color-white
$drawer-toggle__background-color--hover--inverse$color-white
$drawer-toggle__color--hover--inverse$color-gray-dark

Google Analytics

Google analytics are available via the <HelpDrawer> component.

Analytics event tracking is disabled by default.

Enable event tracking

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

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

On application 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

When to use

  • When users need content to remain viewable while also allowing the user to views/interacts with the main page.
  • When the content is longer than 2 sentences.
  • When the content needs to be available at a particular point in the process, but doesn't need to be included on the main page.
  • When the content just needs to be available at the user's discretion, to provide additional details or context.
  • When users may need additional information to complete the task than can be supplied on the main page without overwhelming the primary content.

When to consider alternatives

  • When the content is timely/urgent, or critical to the action being taken.
  • When the content is intended to clarify or call attention to other content on the page.
  • When the content must be displayed without being initiated by a user action.
  • When additional information is necessary to the primary information the user is interacting with.

Usage

  • Link text used to trigger the help drawer should be specific and descriptive.
    • Avoid using only "Learn more" to link to help drawer content
    • Limit the amount of link text
  • Drawer content area should include a close button clearly at the top.

Accessibility

  • Focus should move to the content in the help drawer after the user has opened it.
  • Drawer should support keyboard navigation.
    • Enter and 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

The property hasFocusTrap is an available option that will prevent keyboard focus from leaving the confines of the HelpDrawer when enabled.

When the property hasFocusTrap is enabled...

  • Keyboard focus is trapped within the HelpDrawer component.
  • Pressing the escape key will close the Drawer.

A focus trap should not be used when it's anticipated that the user will rely on the Drawer as a reference resource for doing something outside of the Drawer. For instance, if the user is completing a form, Drawer may contain a reference guide defining specific requirements.

However, there are times when it makes sense to trap focus within the Drawer. One occassion where it can benefit the user is when the Drawer is anticipated to fill the viewport of a screen, i.e., mobile layout.