SwipeableDrawer API
Demos
For examples and details on the usage of this React component, visit the component demo pages:
Import
import SwipeableDrawer from '@mui/material/SwipeableDrawer';
// or
import { SwipeableDrawer } from '@mui/material';Props
Props of the Drawer component are also available.
Callback fired when the component requests to be closed.
Type:
funcSignature:
function(event: React.SyntheticEvent<{}>) => voideventThe event source of the callback.
Callback fired when the component requests to be opened.
Type:
funcSignature:
function(event: React.SyntheticEvent<{}>) => voideventThe event source of the callback.
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).
Type:
func | boolDefault:
falseDisable the backdrop transition. This can improve the FPS on low-end devices.
Type:
boolDefault:
falseIf 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.
Type:
boolDefault:
falseIf 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.
Type:
boolDefault:
typeof navigator !== 'undefined' && /iPad|iPhone|iPod/.test(navigator.userAgent)Affects how far the drawer must be opened/closed to change its state. Specified as percent (0-1) of the width of the drawer
Type:
numberDefault:
0.52Defines, from which (average) velocity on, the swipe is defined as complete although hysteresis isn't reached. Good threshold is between 250 - 1000 px/s
Type:
numberDefault:
450The width of the left most (or right most) area in px that the drawer can be swiped open from.
Type:
numberDefault:
20The duration for the transition, in milliseconds. You may specify a single timeout for all transitions, or individually with an object.
Type:
number | { appear?: number, enter?: number, exit?: number }Default:
{
enter: theme.transitions.duration.enteringScreen,
exit: theme.transitions.duration.leavingScreen,
}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
The following class names are useful for styling with CSS (the state classes are marked).
To learn more, visit the component customization page.
Styles applied to the root element if variant="permanent or persistent".
Styles applied to the Paper component if anchor="left".
Styles applied to the Paper component if anchor="right".
Styles applied to the Paper component if anchor="top".
Styles applied to the Paper component if anchor="bottom".
Styles applied to the Paper component if anchor="left" and variant is not "temporary".
Styles applied to the Paper component if anchor="top" and variant is not "temporary".
Styles applied to the Paper component if anchor="right" and variant is not "temporary".
Styles applied to the Paper component if anchor="bottom" and variant is not "temporary".
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
styleOverridesproperty in a custom theme.