Skip to content

SwipeableDrawer API

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

Demos

Import

import SwipeableDrawer from '@mui/material/SwipeableDrawer';
// or
import { SwipeableDrawer } from '@mui/material';

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

Props

Props of the Drawer component are also available.

NameTypeDefaultDescription
onClose*func-

Callback fired when the component requests to be closed.

Signature:function(event: React.SyntheticEvent<{}>) => void
  • event The event source of the callback.
onOpen*func-

Callback fired when the component requests to be opened.

Signature:function(event: React.SyntheticEvent<{}>) => void
  • event The event source of the callback.
allowSwipeInChildrenfunc
| bool
false

If set to true, the swipe event will open the drawer even if the user begins the swipe on one of the drawer's children. This can be useful in scenarios where the drawer is partially visible. You can customize it further with a callback that determines which children the user can drag over to open the drawer (for example, to ignore other elements that handle touch move events, like sliders).

childrennode-

The content of the component.

disableBackdropTransitionboolfalse

Disable the backdrop transition. This can improve the FPS on low-end devices.

disableDiscoveryboolfalse

If true, touching the screen near the edge of the drawer will not slide in the drawer a bit to promote accidental discovery of the swipe gesture.

disableSwipeToOpenbooltypeof navigator !== 'undefined' && /iPad|iPhone|iPod/.test(navigator.userAgent)

If true, swipe to open is disabled. This is useful in browsers where swiping triggers navigation actions. Swipe to open is disabled on iOS browsers by default.

hysteresisnumber0.52

Affects how far the drawer must be opened/closed to change its state. Specified as percent (0-1) of the width of the drawer

minFlingVelocitynumber450

Defines, from which (average) velocity on, the swipe is defined as complete although hysteresis isn't reached. Good threshold is between 250 - 1000 px/s

openboolfalse

If true, the component is shown.

SwipeAreaPropsobject-

The element is used to intercept the touch events on the edge.

swipeAreaWidthnumber20

The width of the left most (or right most) area in px that the drawer can be swiped open from.

transitionDurationnumber
| { appear?: number, enter?: number, exit?: number }
{ enter: theme.transitions.duration.enteringScreen, exit: theme.transitions.duration.leavingScreen, }

The duration for the transition, in milliseconds. You may specify a single timeout for all transitions, or individually with an object.

The ref is forwarded to the root element.

Inheritance

While not explicitly documented above, the props of the Drawer component are also available in SwipeableDrawer. You can take advantage of this to target nested components.

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
.MuiSwipeableDrawer-dockeddockedStyles applied to the root element if variant="permanent or persistent".
.MuiSwipeableDrawer-modalmodalStyles applied to the Modal component.
.MuiSwipeableDrawer-paperpaperStyles applied to the Paper component.
.MuiSwipeableDrawer-paperAnchorBottompaperAnchorBottomStyles applied to the Paper component if anchor="bottom".
.MuiSwipeableDrawer-paperAnchorDockedBottompaperAnchorDockedBottomStyles applied to the Paper component if anchor="bottom" and variant is not "temporary".
.MuiSwipeableDrawer-paperAnchorDockedLeftpaperAnchorDockedLeftStyles applied to the Paper component if anchor="left" and variant is not "temporary".
.MuiSwipeableDrawer-paperAnchorDockedRightpaperAnchorDockedRightStyles applied to the Paper component if anchor="right" and variant is not "temporary".
.MuiSwipeableDrawer-paperAnchorDockedToppaperAnchorDockedTopStyles applied to the Paper component if anchor="top" and variant is not "temporary".
.MuiSwipeableDrawer-paperAnchorLeftpaperAnchorLeftStyles applied to the Paper component if anchor="left".
.MuiSwipeableDrawer-paperAnchorRightpaperAnchorRightStyles applied to the Paper component if anchor="right".
.MuiSwipeableDrawer-paperAnchorToppaperAnchorTopStyles applied to the Paper component if anchor="top".
.MuiSwipeableDrawer-rootrootStyles applied to the root element.

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