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 of the Drawer component are also available.
Name | Type | Default | Description |
---|---|---|---|
onClose* | func | - | Callback fired when the component requests to be closed. Signature: function(event: React.SyntheticEvent<{}>) => void
|
onOpen* | func | - | Callback fired when the component requests to be opened. Signature: function(event: React.SyntheticEvent<{}>) => void
|
allowSwipeInChildren | func | 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). |
children | node | - | The content of the component. |
disableBackdropTransition | bool | false | Disable the backdrop transition. This can improve the FPS on low-end devices. |
disableDiscovery | bool | false | If |
disableSwipeToOpen | bool | typeof navigator !== 'undefined' && /iPad|iPhone|iPod/.test(navigator.userAgent) | If |
hysteresis | number | 0.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 |
minFlingVelocity | number | 450 | 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 |
open | bool | false | If |
SwipeAreaProps | object | - | The element is used to intercept the touch events on the edge. |
swipeAreaWidth | number | 20 | The width of the left most (or right most) area in |
transitionDuration | number | { 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. |
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.
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 |
---|---|---|
.MuiSwipeableDrawer-docked | docked | Styles applied to the root element if variant="permanent or persistent" . |
.MuiSwipeableDrawer-modal | modal | Styles applied to the Modal component. |
.MuiSwipeableDrawer-paper | paper | Styles applied to the Paper component. |
.MuiSwipeableDrawer-paperAnchorBottom | paperAnchorBottom | Styles applied to the Paper component if anchor="bottom" . |
.MuiSwipeableDrawer-paperAnchorDockedBottom | paperAnchorDockedBottom | Styles applied to the Paper component if anchor="bottom" and variant is not "temporary". |
.MuiSwipeableDrawer-paperAnchorDockedLeft | paperAnchorDockedLeft | Styles applied to the Paper component if anchor="left" and variant is not "temporary". |
.MuiSwipeableDrawer-paperAnchorDockedRight | paperAnchorDockedRight | Styles applied to the Paper component if anchor="right" and variant is not "temporary". |
.MuiSwipeableDrawer-paperAnchorDockedTop | paperAnchorDockedTop | Styles applied to the Paper component if anchor="top" and variant is not "temporary". |
.MuiSwipeableDrawer-paperAnchorLeft | paperAnchorLeft | Styles applied to the Paper component if anchor="left" . |
.MuiSwipeableDrawer-paperAnchorRight | paperAnchorRight | Styles applied to the Paper component if anchor="right" . |
.MuiSwipeableDrawer-paperAnchorTop | paperAnchorTop | Styles applied to the Paper component if anchor="top" . |
.MuiSwipeableDrawer-root | root | Styles applied to the root element. |
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.
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.