Drawer API
API reference docs for the React Drawer component. Learn about the props, CSS, and other APIs of this exported module.
Component demos
Import
import Drawer from '@mui/joy/Drawer';
// or
import { Drawer } from '@mui/joy';
The navigation drawers (or "sidebars") provide ergonomic access to destinations in a site or app functionality such as switching accounts.
Props of the native component are also available.
Name | Type | Default | Description |
---|---|---|---|
open* | bool | If | |
anchor | 'bottom' | 'left' | 'right' | 'top' | 'left' | Side from which the drawer will appear. |
color | 'danger' | 'neutral' | 'primary' | 'success' | 'warning' | 'neutral' | The color of the component. It supports those theme colors that make sense for this component. To learn how to add your own colors, check out Themed components—Extend colors. |
component | elementType | The component used for the root node. Either a string to use a HTML element or a component. | |
container | HTML element | func | An HTML element or function that returns one. The | |
disableAutoFocus | bool | false | If |
disableEnforceFocus | bool | false | If |
disableEscapeKeyDown | bool | false | If |
disablePortal | bool | false | The |
disableRestoreFocus | bool | false | If |
disableScrollLock | bool | false | Disable the scroll lock behavior. |
hideBackdrop | bool | false | If |
invertedColors | bool | false | If |
onClose | func | Callback fired when the component requests to be closed. The Signature: function(event: object, reason: string) => void
| |
size | 'sm' | 'md' | 'lg' | 'md' | The size of the component. To learn how to add custom sizes to the component, check out Themed components—Extend sizes. |
slotProps | { backdrop?: func | object, content?: func | object, root?: func | object } | {} | The props used for each slot inside. |
slots | { backdrop?: elementType, content?: elementType, root?: elementType } | {} | The components used for each slot inside. See Slots API below for more details. |
variant | 'outlined' | 'plain' | 'soft' | 'solid' | 'plain' | The global variant to use. To learn how to add your own variants, check out Themed components—Extend variants. |
ref
is forwarded to the root element.To learn how to customize the slot, check out the Overriding component structure guide.
Slot name | Class name | Default component | Description |
---|---|---|---|
root | .MuiDrawer-root | 'div' | The component that renders the root. |
backdrop | .MuiDrawer-backdrop | 'div' | The component that renders the backdrop. |
content | .MuiDrawer-content | 'div' | The component that renders the content of the drawer. |
These class names are useful for styling with CSS. They are applied to the component's slots when specific states are triggered.
Class name | Rule name | Description |
---|---|---|
.MuiDrawer-colorContext | colorContext | Class name applied to the root element when color inversion is triggered. |
.MuiDrawer-colorDanger | colorDanger | Class name applied to the root element if color="danger" . |
.MuiDrawer-colorNeutral | colorNeutral | Class name applied to the root element if color="neutral" . |
.MuiDrawer-colorPrimary | colorPrimary | Class name applied to the root element if color="primary" . |
.MuiDrawer-colorSuccess | colorSuccess | Class name applied to the root element if color="success" . |
.MuiDrawer-colorWarning | colorWarning | Class name applied to the root element if color="warning" . |
.MuiDrawer-sizeLg | sizeLg | Class name applied to the root element if size="lg" . |
.MuiDrawer-sizeMd | sizeMd | Class name applied to the root element if size="md" . |
.MuiDrawer-sizeSm | sizeSm | Class name applied to the root element if size="sm" . |
.MuiDrawer-variantOutlined | variantOutlined | Class name applied to the root element if variant="outlined" . |
.MuiDrawer-variantPlain | variantPlain | Class name applied to the root element if variant="plain" . |
.MuiDrawer-variantSoft | variantSoft | Class name applied to the root element if variant="soft" . |
.MuiDrawer-variantSolid | variantSolid | Class name applied to the root element if variant="solid" . |
You can override the style of the component using one of these customization options:
- With a global class name.
- With a rule name as part of the component's
styleOverrides
property in a custom theme.