Control interaction flow with simple, extensible drawers.
Drawers are used occasionally in our application, when the user is required to make choices before they can proceed. Here are some examples:
Editing user settings: Allowing users to update profile details or notification preferences without navigating away from the main dashboard.
Viewing detailed logs: Displaying event logs, email histories, or system activity in a collapsible side panel for quick reference.
Initiating workflows: Providing a structured step-by-step interface for setting up automations, integrations, or campaign sequences.
A Drawer consists of several components:
Drawer
DrawerHeader
title prop.DrawerTitle
DrawerBody
DrawerFooter
DrawerInset
The components can be imported via:
At it's simplest, a Drawer will require:
isOpen prop
onClose prop
isOpen state accordingly.title prop
DrawerBody
DrawerBody is required for the body to handle overflow scrolling correctly.DrawerFooter, with buttons or other actions
The drawer component accepts a few callbacks related to its open state:
onClose - this is called when the drawer should be closed (for example, when the "close" "X" button is clicked)
isOpen state to false - otherwise, the drawer will stay openonOpen - this is called when the drawer first renders into the DOM
isOpen state is controlled from outside the drawer, this
callback wouldn't be used to set isOpen. Instead, this can be used to
react to a state change from closed to opened if isOpen is controlled
by another parent component in the apponCloseComplete - when a drawer closes, it will animate out, and unmount after
the animation. This is called when the drawer fully unmounts, after the animation is finishedFor example, open devtools and see the console logs on the below drawer:
By default, drawers are dismissable and will close when:
Depending on the use case, it may be necessary to disable one or more of these behaviors. Each of the dismissals can be controlled via a prop:
shouldShowCloseButton
false, the close button in the header won't be rendered.shouldCloseOnOverlayClick
false, clicking the overlay won't close the drawer.shouldCloseOnEscapePress
false, pressing the "Escape" key won't close the drawer.Additionally, there is an isDismissable prop, which is a shortcut for disabling all of the above.
Note: The individual props, if set, will still take precedence over the isDismissable setting.
By default, the drawer will be on the right side of the screen. If you need to change the placement, you can use the placement prop.
If you have a small amount of content, you can use the size prop to make the drawer smaller.
By default, drawers render an overlay. You can disable this by setting the withOverlay prop to false.
By default DrawerBody contains padding to keep the content from the edges of the drawer.
In some cases, it may be necessary for the content to stretch all the way to the edges -
for example, when showing a full-width image or table.
To make this possible, the DrawerInset component can be used:
To make drawer's accessible, the component contains the following features:
initialFocusIndex propPlumaDrawer extends BoxDefault:125
The duration (in ms) for the modal animation.
By default, the modal will focus the first focusable element. You can override this by setting the index of the focusable element you want to focus instead.
A shortcut to set shouldShowCloseButton, shouldCloseOnOverlayClick, and shouldCloseOnEscapePress to false.
The other prop values still take precedence, if set, even when isDismissable is true.
Whether the modal is open.
Called when the modal is requesting to be closed. For example, when clicking the close button, clicking the overlay, or pressing the Escape key.
Called when the modal finishes closing (after the close animation finishes).
Called when the modal is opened.
The placement of the drawer.
Whether onClose should be called when the Escape key is pressed.
Whether onClose should be called when the overlay is clicked.
Whether a close button should be displayed in the drawer.
The size of the drawer.
A special prop containing all the other modal primitive props for use with the ModalsManager.
An optional subtitle displayed below the title.
Only displayed when title is also provided.
The title of the drawer.
Whether or not the drawer should have an overlay.