Skip to content

Drawer API

API reference docs for the React Drawer component. Learn about the props, CSS, and other APIs of this exported module.

Demos

Import

import Drawer from '@mui/joy/Drawer';
// or
import { Drawer } from '@mui/joy';

Learn about the difference by reading this guide on minimizing bundle size.



The navigation drawers (or "sidebars") provide ergonomic access to destinations in a site or app functionality such as switching accounts.

Props

Props of the native component are also available.

NameTypeDefaultDescription
open*bool-

If true, the component is shown.

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.

componentelementType-

The component used for the root node. Either a string to use a HTML element or a component.

containerHTML element
| func
-

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.

disableAutoFocusboolfalse

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.

disableEnforceFocusboolfalse

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.

disableEscapeKeyDownboolfalse

If true, hitting escape will not fire the onClose callback.

disablePortalboolfalse

The children will be under the DOM hierarchy of the parent component.

disableRestoreFocusboolfalse

If true, the modal will not restore focus to previously focused element once modal is hidden or unmounted.

disableScrollLockboolfalse

Disable the scroll lock behavior.

hideBackdropboolfalse

If true, the backdrop is not rendered.

invertedColorsboolfalse

If true, the children with an implicit color prop invert their colors to match the component's variant and color.

onClosefunc-

Callback fired when the component requests to be closed. The reason parameter can optionally be used to control the response to onClose.

Signature:function(event: object, reason: string) => void
  • event The event source of the callback.
  • reason Can be: "escapeKeyDown", "backdropClick", "closeClick".
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.

The ref is forwarded to the root element.

Slots

To learn how to customize the slot, check out the Overriding component structure guide.

Slot nameClass nameDefault componentDescription
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.

CSS classes

These class names are useful for styling with CSS. They are applied to the component's slots when specific states are triggered.

Class nameRule nameDescription
.MuiDrawer-colorContextcolorContextClass name applied to the root element when color inversion is triggered.
.MuiDrawer-colorDangercolorDangerClass name applied to the root element if color="danger".
.MuiDrawer-colorNeutralcolorNeutralClass name applied to the root element if color="neutral".
.MuiDrawer-colorPrimarycolorPrimaryClass name applied to the root element if color="primary".
.MuiDrawer-colorSuccesscolorSuccessClass name applied to the root element if color="success".
.MuiDrawer-colorWarningcolorWarningClass name applied to the root element if color="warning".
.MuiDrawer-hiddenhiddenClass name applied to the root element when open is false.
.MuiDrawer-sizeLgsizeLgClass name applied to the root element if size="lg".
.MuiDrawer-sizeMdsizeMdClass name applied to the root element if size="md".
.MuiDrawer-sizeSmsizeSmClass name applied to the root element if size="sm".
.MuiDrawer-variantOutlinedvariantOutlinedClass name applied to the root element if variant="outlined".
.MuiDrawer-variantPlainvariantPlainClass name applied to the root element if variant="plain".
.MuiDrawer-variantSoftvariantSoftClass name applied to the root element if variant="soft".
.MuiDrawer-variantSolidvariantSolidClass name applied to the root element if variant="solid".

You can override the style of the component using one of these customization options:

Source code

If you did not find the information in this page, consider having a look at the implementation of the component for more detail.