Drawer
Displays a panel that slides in from the edge of the screen, containing supplementary content.
Installation
The above command is for individual installation only. You may skip this step if @nextui-org/react
is already installed globally.
Import
NextUI exports 5 drawer-related components:
- Drawer: The main component to display a drawer.
- DrawerContent: The wrapper of the other drawer components.
- DrawerHeader: The header of the drawer.
- DrawerBody: The body of the drawer.
- DrawerFooter: The footer of the drawer.
Usage
When the drawer opens:
- Focus is bounded within the drawer and set to the first tabbable element.
- Content behind a drawer is inert, meaning that users cannot interact with it.
Sizes
Non-dismissible
By default, the drawer can be closed by clicking on the overlay or pressing the Esc key. You can disable this behavior by setting the following properties:
- Set the
isDismissable
property tofalse
to prevent the drawer from closing when clicking on the overlay. - Set the
isKeyboardDismissDisabled
property totrue
to prevent the drawer from closing when pressing the Esc key.
Drawer placement
The drawer can be placed on any edge of the screen using the placement
prop:
left
(default)right
top
bottom
With Form
The Drawer
handles the focus within the drawer content. It means that you can use the drawer with
form elements without any problem. The focus returns to the trigger when the drawer closes.
Note: You can add the
autoFocus
prop to the firstInput
component to focus it when the drawer opens.
Backdrop
The Drawer
component has a backdrop
prop to show a backdrop behind the drawer. The backdrop can be
either transparent
, opaque
or blur
. The default value is opaque
.
Custom Motion
Drawer offers a motionProps
property to customize the enter
/ exit
animation.
Learn more about Framer motion variants here.
Custom Styles
The Drawer component design is inspired by Luma.
Slots
- wrapper: The wrapper slot of the drawer. It wraps the
base
and thebackdrop
slots. - base: The main slot of the drawer content.
- backdrop: The backdrop slot, it is displayed behind the drawer.
- header: The header of the drawer, it is displayed at the top of the drawer.
- body: The body of the drawer, it is displayed in the middle of the drawer.
- footer: The footer of the drawer, it is displayed at the bottom of the drawer.
- closeButton: The close button of the drawer.
Data Attributes
Drawer
has the following attributes on the base
element:
- data-open: When the drawer is open. Based on drawer state.
- data-dismissable:
When the drawer is dismissable. Based on
isDismissable
prop.
Accessibility
- Content outside the drawer is hidden from assistive technologies while it is open.
- The drawer optionally closes when interacting outside, or pressing the Esc key.
- Focus is moved into the drawer on mount, and restored to the trigger element on unmount.
- While open, focus is contained within the drawer, preventing the user from tabbing outside.
- Scrolling the page behind the drawer is prevented while it is open, including in mobile browsers.
API
Drawer Props
Prop | Type | Default |
children |
| |
size |
| "md" |
radius |
| "lg" |
placement |
| "right" |
isOpen |
| |
defaultOpen |
| |
isDismissable |
| true |
isKeyboardDismissDisabled |
| false |
shouldBlockScroll |
| true |
hideCloseButton |
| false |
closeButton |
| |
motionProps |
| |
portalContainer |
| "document.body" |
disableAnimation |
| false |
classNames |
|
Drawer Events
Prop | Type | Default |
onOpenChange |
| |
onClose |
|