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
Layout Alternatives
A header and/or footer can have a "sticky" position if the following properties are applied to their respective elements:
isHeaderSticky
isFooterSticky
Code
React
Name | Type | Default | Description |
---|---|---|---|
ariaLabel | string | Gives more context to screen readers on the Drawer close button. | |
closeButtonText | ReactNode | ||
closeButtonVariation | ButtonVariation | ||
className | string | ||
footerBody | ReactNode | ||
footerTitle | string | ||
hasFocusTrap | boolean | false | Enables focus trap functionality within Drawer. |
heading required | ReactNode | Text for the Drawer heading. Required because the heading will be focused on mount. | |
headingId | string | 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> |
headingRef | MutableRefObject<any> | Ref to heading element | |
isHeaderSticky | boolean | Enables "sticky" position of Drawer header element. | |
isFooterSticky | boolean | Enables "sticky" position of Drawer footer element. | |
onCloseClick required | (event: MouseEvent<Element, MouseEvent> | KeyboardEvent<Element>) => void |
<DrawerToggle>
Name | Type | Default | Description |
---|---|---|---|
children required | ReactNode | Label text or HTML DrawerToggle content. | |
className | string | Additional classes to be added to the root button element. Additional classes for the toggle button anchor element. | |
disabled | boolean | ||
href | string | When provided, the root component will render as an <a> element
rather than button . | |
inputRef | ButtonRef | Access a reference to the button or a element | |
isAlternate | boolean | Applies the alternate color to a Button. By default, Button
uses the main color. | |
onClick | (...args: any[]) => any | Returns the SyntheticEvent .
Not called when the Button is disabled. | |
onDark | boolean | Defines a color palette best used when Button is placed on a dark background-color. By default, Button uses a light color palette. | |
size | ButtonSize | ||
type | "button" | "submit" | "reset" | Button type attribute | |
variation | ButtonVariation | A string corresponding to Button variation classes. | |
analytics | boolean | Analytics events tracking is enabled by default. Set this value to false to
disable tracking for this component instance. | |
analyticsLabelOverride | string | An override for the dynamic content sent to analytics services. By default this content comes from the heading. In cases where this component’s heading may contain sensitive information, use this prop to override what is sent to analytics. | |
analyticsEventTypeOverride | string | 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) => void | 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 . | |
analyticsParentHeading | string | If needed for analytics, pass heading text of parent component of button. | |
analyticsParentType | string | If needed for analytics, pass type of parent component of button. | |
drawerOpen required | boolean | Determines if Drawer is open or closed. This value is used to re-focus the toggle that opened the drawer when the drawer closes. | |
inline | boolean | Adds display: inline to the DrawerToggle. | |
showDrawer required | (string: any) => 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.
Name | Type | Default | Description |
---|---|---|---|
ariaLabel | string | Gives more context to screen readers on the Drawer close button. | |
closeButtonText | ReactNode | ||
closeButtonVariation | ButtonVariation | ||
className | string | ||
footerBody | ReactNode | ||
footerTitle | string | ||
hasFocusTrap | boolean | Enables focus trap functionality within Drawer. | |
heading required | ReactNode | Text for the Drawer heading. Required because the heading will be focused on mount. | |
headingId | string | A unique id to be used on heading element to label multiple instances of Drawer. | |
headingLevel | "1" | "2" | "3" | "4" | "5" | Heading type to override default <h3> | |
headingRef | MutableRefObject<any> | Ref to heading element | |
isHeaderSticky | boolean | Enables "sticky" position of Drawer header element. | |
isFooterSticky | boolean | Enables "sticky" position of Drawer footer element. | |
onCloseClick required | (event: MouseEvent<Element, MouseEvent> | KeyboardEvent<Element>) => void | ||
analytics | boolean | Analytics events tracking is enabled by default. Set this value to false to
disable tracking for this component instance. | |
analyticsLabelOverride | string | An override for the dynamic content sent to analytics services. By default this content comes from the heading. In cases where this component’s heading may contain sensitive information, use this prop to override what is sent to analytics. | |
analyticsEventTypeOverride | string | 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) => void | 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 . |
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 CSS variables can be overridden to customize Drawer components:
Analytics
This component has analytics tracking available. Please see our developer documentation about using analytics in the design system.
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
andSpace
to select the highlighted item.Tab
to move the focus sequentially through the list of focusable itemsShift + 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.
Component maturity
For more information about how we tested and validated our work for each checklist item, read our component maturity documentation.