Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions docs/data/material/components/app-bar/DrawerAppBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ function DrawerAppBar(props) {
variant="temporary"
open={mobileOpen}
onClose={handleDrawerToggle}
ModalProps={{
keepMounted: true, // Better open performance on mobile.
slotProps={{
root: {
keepMounted: true, // Better open performance on mobile.
},
}}
sx={{
display: { xs: 'block', sm: 'none' },
Expand Down
6 changes: 4 additions & 2 deletions docs/data/material/components/app-bar/DrawerAppBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@ export default function DrawerAppBar(props: Props) {
variant="temporary"
open={mobileOpen}
onClose={handleDrawerToggle}
ModalProps={{
keepMounted: true, // Better open performance on mobile.
slotProps={{
root: {
keepMounted: true, // Better open performance on mobile.
},
}}
sx={{
display: { xs: 'block', sm: 'none' },
Expand Down
8 changes: 5 additions & 3 deletions docs/data/material/components/drawers/drawers.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,15 @@ On iOS, also set `disableDiscovery`: Safari doesn't fire click events on the chi
The Modal used internally by the Swipeable Drawer has the `keepMounted` prop set by default.
This means that the contents of the drawer are always present in the DOM.

You can change this default behavior with the `ModalProps` prop, but you may encounter issues with `keepMounted: false` in React 18.
You can change this default behavior with the `slotProps.root` prop, but you may encounter issues with `keepMounted: false` in React 18.

```jsx
<Drawer
variant="temporary"
ModalProps={{
keepMounted: false,
slotProps={{
root: {
keepMounted: false,
},
}}
/>
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,10 @@ function DashboardSidebar({
variant="temporary"
open={expanded}
onClose={handleSetSidebarExpanded(false)}
ModalProps={{
keepMounted: true, // Better open performance on mobile.
slotProps={{
root: {
keepMounted: true, // Better open performance on mobile.
},
}}
sx={[
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,10 @@ export default function DashboardSidebar({
variant="temporary"
open={expanded}
onClose={handleSetSidebarExpanded(false)}
ModalProps={{
keepMounted: true, // Better open performance on mobile.
slotProps={{
root: {
keepMounted: true, // Better open performance on mobile.
},
}}
sx={[
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,17 @@ The Drawer's `BackdropProps` prop was deprecated in favor of `slotProps.backdrop
/>
```

### ModalProps

The Drawer's `ModalProps` prop was deprecated in favor of `slotProps.root`:

```diff
<Drawer
- ModalProps={modalProps}
+ slotProps={{ root: modalProps }}
/>
```

### PaperProps

The Drawer's `PaperProps` prop was deprecated in favor of `slotProps.paper`:
Expand Down
7 changes: 6 additions & 1 deletion docs/pages/material-ui/api/drawer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@
"classes": { "type": { "name": "object" }, "additionalInfo": { "cssApi": true } },
"elevation": { "type": { "name": "custom", "description": "integer" }, "default": "16" },
"hideBackdrop": { "type": { "name": "bool" }, "default": "false" },
"ModalProps": { "type": { "name": "object" }, "default": "{}" },
"ModalProps": {
"type": { "name": "object" },
"default": "{}",
"deprecated": true,
"deprecationInfo": "Use <code>slotProps.root</code> instead. This prop will be removed in a future major release. See <a href=\"/material-ui/migration/migrating-from-deprecated-apis/\">Migrating from deprecated APIs</a> for more details."
},
"onClose": {
"type": { "name": "func" },
"signature": {
Expand Down
4 changes: 4 additions & 0 deletions packages/mui-codemod/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1283,11 +1283,13 @@ npx @mui/codemod@latest deprecations/drawer-classes <path>
<Drawer
- BackdropComponent={CustomBackdrop}
- BackdropProps={{ transitionDuration: 300 }}
- ModalProps={{ keepMounted: true }}
- PaperProps={{ elevation: 20 }}
- SlideProps={{ direction: 'right' }}
+ slots={{ backdrop: CustomBackdrop }}
+ slotProps={{
+ backdrop: { transitionDuration: 300 },
+ root: { keepMounted: true },
+ paper: { elevation: 20 },
+ transition: { direction: 'right' },
+ }}
Expand All @@ -1301,11 +1303,13 @@ The same applies to `SwipeableDrawer`.
defaultProps: {
- BackdropComponent: CustomBackdrop,
- BackdropProps: { transitionDuration: 300 },
- ModalProps: { keepMounted: true },
- PaperProps: { elevation: 20 },
- SlideProps: { direction: 'right' },
+ slots: { backdrop: CustomBackdrop },
+ slotProps: {
+ backdrop: { transitionDuration: 300 },
+ root: { keepMounted: true },
+ paper: { elevation: 20 },
+ transition: { direction: 'right' },
+ },
Expand Down
15 changes: 15 additions & 0 deletions packages/mui-codemod/src/deprecations/drawer-props/drawer-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@ export default function transformer(file, api, options) {
slotName: 'backdrop',
});

movePropIntoSlotProps(j, {
root,
packageName: options.packageName,
componentName: 'Drawer',
propName: 'ModalProps',
slotName: 'root',
});
movePropIntoSlotProps(j, {
root,
packageName: options.packageName,
componentName: 'SwipeableDrawer',
propName: 'ModalProps',
slotName: 'root',
});

movePropIntoSlotProps(j, {
root,
packageName: options.packageName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { Drawer as MyDrawer, SwipeableDrawer as MySwipeableDrawer } from '@mui/m
<Drawer BackdropComponent={Backdrop} BackdropProps={{ transitionDuration: 300 }} />;
<SwipeableDrawer BackdropComponent={Backdrop} BackdropProps={{ transitionDuration: 300 }} />;

<Drawer ModalProps={{ keepMounted: true }} />;
<SwipeableDrawer ModalProps={{ keepMounted: true }} />;

<Drawer PaperProps={{ elevation: 20 }} />;
<SwipeableDrawer PaperProps={{ elevation: 20 }} />;

Expand All @@ -17,13 +20,15 @@ import { Drawer as MyDrawer, SwipeableDrawer as MySwipeableDrawer } from '@mui/m
<MyDrawer
BackdropComponent={Backdrop}
BackdropProps={{ transitionDuration: 300 }}
ModalProps={{ keepMounted: true }}
PaperProps={{ elevation: 20 }}
SlideProps={{ direction: 'right' }}
TransitionComponent={CustomTransition}
/>;
<MySwipeableDrawer
BackdropComponent={Backdrop}
BackdropProps={{ transitionDuration: 300 }}
ModalProps={{ keepMounted: true }}
PaperProps={{ elevation: 20 }}
SlideProps={{ direction: 'right' }}
TransitionComponent={CustomTransition}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ import { Drawer as MyDrawer, SwipeableDrawer as MySwipeableDrawer } from '@mui/m
backdrop: { transitionDuration: 300 }
}} />;

<Drawer slotProps={{
root: { keepMounted: true }
}} />;
<SwipeableDrawer slotProps={{
root: { keepMounted: true }
}} />;

<Drawer slotProps={{
paper: { elevation: 20 }
}} />;
Expand Down Expand Up @@ -41,6 +48,7 @@ import { Drawer as MyDrawer, SwipeableDrawer as MySwipeableDrawer } from '@mui/m
}}
slotProps={{
backdrop: { transitionDuration: 300 },
root: { keepMounted: true },
paper: { elevation: 20 },
transition: { direction: 'right' }
}} />;
Expand All @@ -51,6 +59,7 @@ import { Drawer as MyDrawer, SwipeableDrawer as MySwipeableDrawer } from '@mui/m
}}
slotProps={{
backdrop: { transitionDuration: 300 },
root: { keepMounted: true },
paper: { elevation: 20 },
transition: { direction: 'right' }
}} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { Drawer as MyDrawer, SwipeableDrawer as MySwipeableDrawer } from '@org/u
<Drawer BackdropComponent={Backdrop} BackdropProps={{ transitionDuration: 300 }} />;
<SwipeableDrawer BackdropComponent={Backdrop} BackdropProps={{ transitionDuration: 300 }} />;

<Drawer ModalProps={{ keepMounted: true }} />;
<SwipeableDrawer ModalProps={{ keepMounted: true }} />;

<Drawer PaperProps={{ elevation: 20 }} />;
<SwipeableDrawer PaperProps={{ elevation: 20 }} />;

Expand All @@ -14,12 +17,14 @@ import { Drawer as MyDrawer, SwipeableDrawer as MySwipeableDrawer } from '@org/u
<MyDrawer
BackdropComponent={Backdrop}
BackdropProps={{ transitionDuration: 300 }}
ModalProps={{ keepMounted: true }}
PaperProps={{ elevation: 20 }}
SlideProps={{ direction: 'right' }}
/>;
<MySwipeableDrawer
BackdropComponent={Backdrop}
BackdropProps={{ transitionDuration: 300 }}
ModalProps={{ keepMounted: true }}
PaperProps={{ elevation: 20 }}
SlideProps={{ direction: 'right' }}
/>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ import { Drawer as MyDrawer, SwipeableDrawer as MySwipeableDrawer } from '@org/u
backdrop: { transitionDuration: 300 }
}} />;

<Drawer slotProps={{
root: { keepMounted: true }
}} />;
<SwipeableDrawer slotProps={{
root: { keepMounted: true }
}} />;

<Drawer slotProps={{
paper: { elevation: 20 }
}} />;
Expand All @@ -33,6 +40,7 @@ import { Drawer as MyDrawer, SwipeableDrawer as MySwipeableDrawer } from '@org/u
}}
slotProps={{
backdrop: { transitionDuration: 300 },
root: { keepMounted: true },
paper: { elevation: 20 },
transition: { direction: 'right' }
}} />;
Expand All @@ -42,6 +50,7 @@ import { Drawer as MyDrawer, SwipeableDrawer as MySwipeableDrawer } from '@org/u
}}
slotProps={{
backdrop: { transitionDuration: 300 },
root: { keepMounted: true },
paper: { elevation: 20 },
transition: { direction: 'right' }
}} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,25 @@ fn({
},
});

fn({
MuiDrawer: {
defaultProps: {
ModalProps: {
keepMounted: true,
},
},
},
});
fn({
MuiSwipeableDrawer: {
defaultProps: {
ModalProps: {
keepMounted: true,
},
},
},
});

fn({
MuiDrawer: {
defaultProps: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,29 @@ fn({
},
});

fn({
MuiDrawer: {
defaultProps: {
slotProps: {
root: {
keepMounted: true,
}
},
},
},
});
fn({
MuiSwipeableDrawer: {
defaultProps: {
slotProps: {
root: {
keepMounted: true,
}
},
},
},
});

fn({
MuiDrawer: {
defaultProps: {
Expand Down
1 change: 1 addition & 0 deletions packages/mui-material/src/Drawer/Drawer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export interface DrawerProps
/**
* Props applied to the [`Modal`](https://mui.com/material-ui/api/modal/) element.
* @default {}
* @deprecated Use `slotProps.root` instead. This prop will be removed in a future major release. See [Migrating from deprecated APIs](/material-ui/migration/migrating-from-deprecated-apis/) for more details.
*/
ModalProps?: Partial<ModalProps> | undefined;
/**
Expand Down
1 change: 1 addition & 0 deletions packages/mui-material/src/Drawer/Drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ Drawer.propTypes /* remove-proptypes */ = {
/**
* Props applied to the [`Modal`](https://mui.com/material-ui/api/modal/) element.
* @default {}
* @deprecated Use `slotProps.root` instead. This prop will be removed in a future major release. See [Migrating from deprecated APIs](/material-ui/migration/migrating-from-deprecated-apis/) for more details.
*/
ModalProps: PropTypes.object,
/**
Expand Down
16 changes: 16 additions & 0 deletions packages/mui-material/src/Drawer/Drawer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,22 @@ describe('<Drawer />', () => {
});
});

describe('prop: slotProps.root', () => {
it('should forward props to the Modal', () => {
render(
<Drawer
open={false}
slotProps={{ root: { keepMounted: true, 'data-testid': 'drawer-root' } }}
>
<div data-testid="content" />
</Drawer>,
);

expect(screen.getByTestId('drawer-root')).to.have.class(modalClasses.root);
expect(screen.getByTestId('content')).not.to.equal(null);
});
});

describe('slide direction', () => {
it('should return the opposing slide direction', () => {
const MockedSlide = React.forwardRef(function MockedSlide(props, ref) {
Expand Down
Loading