跳转到内容

Drawer API

想要学习更多组件属性和 CSS API,可以查阅 React Drawer 组件的 API 文档。

导入

import Drawer from '@mui/material/Drawer';
// 或
import { Drawer } from '@mui/material';
你可以阅读这个关于最小化捆绑包的指南以了解以上二者的差异。

The props of the Modal component are available when variant="temporary" is set.

组件名称

在主题中,名称“MuiDrawer”可用于提供默认属性(props),或者样式覆盖

属性

原生(Native) 组件的属性也是可用的。

名称类型默认值描述
anchor'bottom'
| 'left'
| 'right'
| 'top'
'left'
Side from which the drawer will appear.
childrennode
The content of the component.
classesobject
Override or extend the styles applied to the component. See CSS API below for more details.
elevationinteger16
The elevation of the drawer.
hideBackdropboolfalse
If true, the backdrop is not rendered.
ModalPropsobject{}
Props applied to the Modal element.
onClosefunc
Callback fired when the component requests to be closed.

Signature:
function(event: object) => void
event: The event source of the callback.
openboolfalse
Control the popup` open state.
PaperPropsobject{}
Props applied to the Paper element.
SlidePropsobject
Props applied to the Slide element.
sxArray<func
| object
| bool>
| func
| object
The system prop that allows defining system overrides as well as additional CSS styles. See the `sx` page for more details.
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.
variant'permanent'
| 'persistent'
| 'temporary'
'temporary'
The variant to use.

ref 则会被传递到根元素中。

CSS

规则名称全局类名描述
root.MuiDrawer-rootStyles applied to the root element.
docked.MuiDrawer-dockedStyles applied to the root element if variant="permanent or persistent".
paper.MuiDrawer-paperStyles applied to the Paper component.
paperAnchorLeft.MuiDrawer-paperAnchorLeftStyles applied to the Paper component if anchor="left".
paperAnchorRight.MuiDrawer-paperAnchorRightStyles applied to the Paper component if anchor="right".
paperAnchorTop.MuiDrawer-paperAnchorTopStyles applied to the Paper component if anchor="top".
paperAnchorBottom.MuiDrawer-paperAnchorBottomStyles applied to the Paper component if anchor="bottom".
paperAnchorDockedLeft.MuiDrawer-paperAnchorDockedLeftStyles applied to the Paper component if anchor="left" and variant is not "temporary".
paperAnchorDockedTop.MuiDrawer-paperAnchorDockedTopStyles applied to the Paper component if anchor="top" and variant is not "temporary".
paperAnchorDockedRight.MuiDrawer-paperAnchorDockedRightStyles applied to the Paper component if anchor="right" and variant is not "temporary".
paperAnchorDockedBottom.MuiDrawer-paperAnchorDockedBottomStyles applied to the Paper component if anchor="bottom" and variant is not "temporary".
modal.MuiDrawer-modalStyles applied to the Modal component.

您可以使用组件自定义选项对组件进行个性化:

演示项目