DrawerNew: New
Features
- Traps focus within the drawer and returns focus to the trigger when closed.
- Locks background scrolling.
- Includes a 'Close' button for dismissing the drawer.
- Includes subcomponents to enable easy construction of the drawer's content.
When to use
At Pleo, we use drawers to focus the user's attention on completing a task or viewing details about an item. Our Overlays pattern guidelines explain when to use a drawer instead of a Tooltip, Popover, or Modal.
Task drawer vs. Item drawer
A drawer constructed to complete a task is referred to as a Task drawer, while a drawer constructed to view details about an item is referred to as an Item drawer.
These drawer types are not directly reflected in the API. They are instead a conceptual distinction that helps us design and use drawers effectively.
View the Examples section for demonstrations of both drawer types and consult the Best practices section for guidance on which subcomponents to use in each type.
Examples
Item drawer
A drawer that is used to view details about an item is referred to as an Item drawer. These items could for example be users, vendor cards, or subscriptions. There may be some interactions the user can perform within the drawer. However, the goal is for users to view information about an item, rather than complete an task.
Task drawer
A drawer that is used to complete a task, such as adding an expense or creating a vendor card, is referred to as a Task drawer. The goal of the drawer is to help the user complete the task, and the drawer will close once the task is complete.
Best practices
Drawer.ActionBar
of an Item drawer if multiple actions can be performed on the item in question.Drawer.ActionBar
of a Task drawer.Drawer.Footer
in a Task drawer to signal a decision needs to be made to complete the task at hand.Drawer.Footer
in an Item drawer.Navigating to a drawer
Drawers should always be accessible through a unique link. This allows users to navigate directly to the content of a drawer, both from within and outside the app.
For example, imagine that we have a page with a list of invoices at pleo.io/invoices
, the drawer to add a new invoice should be available at pleo.io/invoices/add-invoice
Accessibility
We use @radix-ui/react-dialog to make the Drawer
accessibile. It adheres to the Dialog WAI-ARIA design pattern.
By default, the first focusable element in the drawer will receive focus when the drawer opens (normally the close button). You can override this by passing an onOpenFocusRef
prop to the Drawer
component, which will set focus on the element with the ref you pass in. You should do this where there is a more relevant field that should receive initial focus, for example the first form field, in accordance with the keyboard interaction guidelines outlined in the WAI-ARIA Dialog design pattern.