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.
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.
Type:'danger'
| 'neutral'
| 'primary'
| 'success'
| 'warning'
Default:'neutral'
The component used for the root node. Either a string to use a HTML element or a component.
Type:elementType
An HTML element or function that returns one. The container
will have the portal children appended to it.
You can also provide a callback, which is called in a React layout effect. This lets you set the container from a ref, and also makes server-side rendering possible.
By default, it uses the body of the top-level document object, so it's simply document.body
most of the time.
Type:HTML element
| func
If true
, the modal will not automatically shift focus to itself when it opens, and replace it to the last focused element when it closes. This also works correctly with any modal children that have the disableAutoFocus
prop.
Generally this should never be set to true
as it makes the modal less accessible to assistive technologies, like screen readers.
Type:bool
Default:false
If true
, the modal will not prevent focus from leaving the modal while open.
Generally this should never be set to true
as it makes the modal less accessible to assistive technologies, like screen readers.
Type:bool
Default:false
If true
, hitting escape will not fire the onClose
callback.
Type:bool
Default:false
The children
will be under the DOM hierarchy of the parent component.
Type:bool
Default:false
If true
, the modal will not restore focus to previously focused element once modal is hidden or unmounted.
Type:bool
Default:false
If true
, the children with an implicit color prop invert their colors to match the component's variant and color.
Type:bool
Default:false
Callback fired when the component requests to be closed. The reason
parameter can optionally be used to control the response to onClose
.
Type:func
function(event: object, reason: string) => void
event
The event source of the callback.reason
Can be:"escapeKeyDown"
,"backdropClick"
,"closeClick"
.
The size of the component.
To learn how to add custom sizes to the component, check out Themed components—Extend sizes.
Type:'sm'
| 'md'
| 'lg'
Default:'md'
The props used for each slot inside.
Type:{ backdrop?: func
| object, content?: func
| object, root?: func
| object }
Default:{}
The components used for each slot inside.
See Slots API below for more details.
Type:{ backdrop?: elementType, content?: elementType, root?: elementType }
Default:{}
The global variant to use.
To learn how to add your own variants, check out Themed components—Extend variants.
Type:'outlined'
| 'plain'
| 'soft'
| 'solid'
Default:'plain'
ref
is forwarded to the root element.To learn how to customize the slot, check out the Overriding component structure guide.
The component that renders the backdrop.
Class name: .MuiDrawer-backdrop
Default component: 'div'
These class names are useful for styling with CSS. They are applied to the component's slots when specific states are triggered.
Class name applied to the root element when color inversion is triggered.
Rule name:colorContext
Class name applied to the root element if color="danger"
.
Rule name:colorDanger
Class name applied to the root element if color="neutral"
.
Rule name:colorNeutral
Class name applied to the root element if color="primary"
.
Rule name:colorPrimary
Class name applied to the root element if color="success"
.
Rule name:colorSuccess
Class name applied to the root element if color="warning"
.
Rule name:colorWarning
Class name applied to the root element if variant="outlined"
.
Rule name:variantOutlined
Class name applied to the root element if variant="plain"
.
Rule name:variantPlain
Class name applied to the root element if variant="soft"
.
Rule name:variantSoft
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.