Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[material-ui][Drawer] Deprecate *Props and complete slots, slotProps #44960

Merged
merged 42 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
47cf38e
deprecate props and complete slots, slotProps
siriwatknp Jan 2, 2025
c2c3f8e
run proptypes and api
siriwatknp Jan 2, 2025
fa08db2
add missing externalForwardedProps
siriwatknp Jan 2, 2025
9f52835
Merge branch 'master' of https://github.com/mui/material-ui into depr…
siriwatknp Jan 6, 2025
8f43bfe
apply mergeSlotProps
siriwatknp Jan 7, 2025
dd61014
fix Drawer spreading props
siriwatknp Jan 7, 2025
0b5d25e
merge style
siriwatknp Jan 7, 2025
3840d2c
update docs
siriwatknp Jan 7, 2025
8bacb6c
fix docs
siriwatknp Jan 7, 2025
b62d0a9
Merge branch 'fix/merge-slot-props-style' into deprecation/drawer
siriwatknp Jan 7, 2025
5f4afc9
update proptypes and api
siriwatknp Jan 7, 2025
cb22da5
add codemod for jsx
siriwatknp Jan 7, 2025
42abe8a
add theme codemod
siriwatknp Jan 7, 2025
440a457
replace deprecated props with slotProps
siriwatknp Jan 7, 2025
f56cf29
run codemod
siriwatknp Jan 7, 2025
1e8626e
add slots test to Drawer
siriwatknp Jan 8, 2025
b4b2d41
Merge branch 'master' into deprecation/drawer
siriwatknp Jan 9, 2025
5157e84
revert ModalProps deprecation
siriwatknp Jan 9, 2025
b8f1916
update migration doc
siriwatknp Jan 9, 2025
401d7ea
skip testWithElement
siriwatknp Jan 9, 2025
95fd952
Merge branch 'master' of https://github.com/mui/material-ui into depr…
siriwatknp Jan 9, 2025
3ca7ddf
fix test
siriwatknp Jan 9, 2025
c43b590
fix paper passing component
siriwatknp Jan 9, 2025
4412f2e
Merge branch 'master' of https://github.com/mui/material-ui into depr…
siriwatknp Jan 10, 2025
15b1190
remove unnecessary fork ref
siriwatknp Jan 10, 2025
527908e
forward component prop to Paper
siriwatknp Jan 10, 2025
39b0ef6
Merge branch 'master' of https://github.com/mui/material-ui into depr…
siriwatknp Jan 15, 2025
f6eeba7
convert root to useSlot
siriwatknp Jan 15, 2025
5371ebf
Merge branch 'master' of https://github.com/mui/material-ui into depr…
siriwatknp Jan 31, 2025
9683fbd
proptypes
siriwatknp Jan 31, 2025
8dd9fea
fix duplicate fields
siriwatknp Feb 3, 2025
3b7d2f8
Merge branch 'master' into deprecation/drawer
siriwatknp Feb 3, 2025
e0a9d1e
Merge branch 'master' of https://github.com/mui/material-ui into depr…
siriwatknp Feb 4, 2025
e4ce474
apply suggestion
siriwatknp Feb 4, 2025
b33b1f3
apply suggestion
siriwatknp Feb 4, 2025
3b7500f
add more slot tests
siriwatknp Feb 4, 2025
d0134d9
added transition slot test
siriwatknp Feb 4, 2025
3a20a13
fix regression test
siriwatknp Feb 4, 2025
2f01e46
add transition spec
siriwatknp Feb 5, 2025
bfa4345
Merge branch 'master' of https://github.com/mui/material-ui into depr…
siriwatknp Feb 5, 2025
f1f7562
Merge branch 'master' of https://github.com/mui/material-ui into depr…
siriwatknp Feb 6, 2025
6136688
apply suggestion
siriwatknp Feb 6, 2025
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
8 changes: 5 additions & 3 deletions docs/data/material/components/drawers/ResponsiveDrawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,15 @@ function ResponsiveDrawer(props) {
open={mobileOpen}
onTransitionEnd={handleDrawerTransitionEnd}
onClose={handleDrawerClose}
ModalProps={{
keepMounted: true, // Better open performance on mobile.
}}
sx={{
display: { xs: 'block', sm: 'none' },
'& .MuiDrawer-paper': { boxSizing: 'border-box', width: drawerWidth },
}}
slotProps={{
root: {
keepMounted: true, // Better open performance on mobile.
},
}}
>
{drawer}
</Drawer>
Expand Down
8 changes: 5 additions & 3 deletions docs/data/material/components/drawers/ResponsiveDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,15 @@ export default function ResponsiveDrawer(props: Props) {
open={mobileOpen}
onTransitionEnd={handleDrawerTransitionEnd}
onClose={handleDrawerClose}
ModalProps={{
keepMounted: true, // Better open performance on mobile.
}}
sx={{
display: { xs: 'block', sm: 'none' },
'& .MuiDrawer-paper': { boxSizing: 'border-box', width: drawerWidth },
}}
slotProps={{
root: {
keepMounted: true, // Better open performance on mobile.
},
}}
>
{drawer}
</Drawer>
Expand Down
4 changes: 1 addition & 3 deletions docs/data/material/components/drawers/SwipeableEdgeDrawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ function SwipeableEdgeDrawer(props) {
onOpen={toggleDrawer(true)}
swipeAreaWidth={drawerBleeding}
disableSwipeToOpen={false}
ModalProps={{
keepMounted: true,
}}
keepMounted
>
<StyledBox
sx={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ export default function SwipeableEdgeDrawer(props: Props) {
onOpen={toggleDrawer(true)}
swipeAreaWidth={drawerBleeding}
disableSwipeToOpen={false}
ModalProps={{
keepMounted: true,
}}
keepMounted
>
<StyledBox
sx={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,45 @@ The Divider's `light` prop was deprecated, Use `sx={{ opacity : "0.6" }}` (or an

## Drawer

Use the [codemod](https://github.com/mui/material-ui/tree/HEAD/packages/mui-codemod#drawer-props) below to migrate the code as described in the following sections:

```bash
npx @mui/codemod@latest deprecations/drawer-props <path>
```

### BackdropProps

The Drawer's `BackdropProps` prop was deprecated in favor of `slotProps.backdrop`:

```diff
<Drawer
- BackdropProps={backdropProps}
+ slotProps={{ backdrop: backdropProps }}
/>
```

### PaperProps

The Drawer's `PaperProps` prop was deprecated in favor of `slotProps.paper`:

```diff
<Drawer
- PaperProps={paperProps}
+ slotProps={{ paper: paperProps }}
/>
```

### SlideProps

The Drawer's `SlideProps` prop was deprecated in favor of `slotProps.transition`:

```diff
<Drawer
- SlideProps={slideProps}
+ slotProps={{ transition: slideProps }}
/>
```

Use the [codemod](https://github.com/mui/material-ui/tree/HEAD/packages/mui-codemod#drawer-classes) below to migrate the code as described in the following sections:

```bash
Expand Down Expand Up @@ -1931,6 +1970,47 @@ The Slider's `componentsProps` prop was deprecated in favor of `slotProps`:
/>
```

## SwipeableDrawer

Use the [codemod](https://github.com/mui/material-ui/tree/HEAD/packages/mui-codemod#drawer-props) below to migrate the code as described in the following sections:

```bash
npx @mui/codemod@latest deprecations/drawer-props <path>
```

### BackdropProps

The SwipeableDrawer's `BackdropProps` prop was deprecated in favor of `slotProps.backdrop`:

```diff
<SwipeableDrawer
- BackdropProps={backdropProps}
+ slotProps={{ backdrop: backdropProps }}
/>
```

### PaperProps

The SwipeableDrawer's `PaperProps` prop was deprecated in favor of `slotProps.paper`:

```diff
<SwipeableDrawer
- PaperProps={paperProps}
+ slotProps={{ paper: paperProps }}
/>
```

### SlideProps

The SwipeableDrawer's `SlideProps` prop was deprecated in favor of `slotProps.transition`:

```diff
<SwipeableDrawer
- SlideProps={slideProps}
+ slotProps={{ transition: slideProps }}
/>
```

## ToggleButtonGroup

Use the [codemod](https://github.com/mui/material-ui/tree/HEAD/packages/mui-codemod#toggle-button-group-classes) below to migrate the code as described in the following sections:
Expand Down
77 changes: 57 additions & 20 deletions docs/pages/material-ui/api/drawer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,31 @@
}
},
"open": { "type": { "name": "bool" }, "default": "false" },
"PaperProps": { "type": { "name": "object" }, "default": "{}" },
"SlideProps": { "type": { "name": "object" } },
"PaperProps": {
"type": { "name": "object" },
"default": "{}",
"deprecated": true,
"deprecationInfo": "use the <code>slotProps.paper</code> prop instead. This prop will be removed in v7. See <a href=\"https://mui.com/material-ui/migration/migrating-from-deprecated-apis/\">Migrating from deprecated APIs</a> for more details."
},
"SlideProps": {
"type": { "name": "object" },
"deprecated": true,
"deprecationInfo": "use the <code>slotProps.transition</code> prop instead. This prop will be removed in v7. See <a href=\"https://mui.com/material-ui/migration/migrating-from-deprecated-apis/\">Migrating from deprecated APIs</a> for more details."
},
"slotProps": {
"type": {
"name": "shape",
"description": "{ backdrop?: func<br>&#124;&nbsp;object, docked?: func<br>&#124;&nbsp;object, paper?: func<br>&#124;&nbsp;object, root?: func<br>&#124;&nbsp;object, transition?: func<br>&#124;&nbsp;object }"
},
"default": "{}"
},
"slots": {
"type": {
"name": "shape",
"description": "{ backdrop?: elementType, docked?: elementType, paper?: elementType, root?: elementType, transition?: elementType }"
},
"default": "{}"
},
"sx": {
"type": {
"name": "union",
Expand Down Expand Up @@ -49,6 +72,38 @@
"import Drawer from '@mui/material/Drawer';",
"import { Drawer } from '@mui/material';"
],
"slots": [
{
"name": "root",
"description": "The component used for the root when the variant is `temporary`.",
"default": "Modal",
"class": "MuiDrawer-root"
},
{
"name": "backdrop",
"description": "The component used for the Modal backdrop.",
"default": "Backdrop",
"class": null
},
{
"name": "docked",
"description": "The component used for the root element when the variant is `permanent` or `persistent`.",
"default": "div",
"class": "MuiDrawer-docked"
},
{
"name": "paper",
"description": "The component used for the paper.",
"default": "Paper",
"class": "MuiDrawer-paper"
},
{
"name": "transition",
"description": "The component used for the transition.\n[Follow this guide](https://mui.com/material-ui/transitions/#transitioncomponent-prop) to learn more about the requirements for this component.",
"default": "Slide",
"class": null
}
],
"classes": [
{
"key": "anchorBottom",
Expand All @@ -74,24 +129,12 @@
"description": "Styles applied to the root element if `anchor=\"top\"`.",
"isGlobal": false
},
{
"key": "docked",
"className": "MuiDrawer-docked",
"description": "Styles applied to the root element if `variant=\"permanent or persistent\"`.",
"isGlobal": false
},
{
"key": "modal",
"className": "MuiDrawer-modal",
"description": "Styles applied to the Modal component.",
"isGlobal": false
},
{
"key": "paper",
"className": "MuiDrawer-paper",
"description": "Styles applied to the Paper component.",
"isGlobal": false
},
{
"key": "paperAnchorBottom",
"className": "MuiDrawer-paperAnchorBottom",
Expand Down Expand Up @@ -147,12 +190,6 @@
"description": "Styles applied to the Paper component if `anchor=\"top\"`.",
"isGlobal": false,
"isDeprecated": true
},
{
"key": "root",
"className": "MuiDrawer-root",
"description": "Styles applied to the root element.",
"isGlobal": false
}
],
"spread": true,
Expand Down
28 changes: 27 additions & 1 deletion docs/pages/material-ui/api/swipeable-drawer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,25 @@
"hysteresis": { "type": { "name": "number" }, "default": "0.52" },
"minFlingVelocity": { "type": { "name": "number" }, "default": "450" },
"open": { "type": { "name": "bool" }, "default": "false" },
"SwipeAreaProps": { "type": { "name": "object" } },
"slotProps": {
"type": {
"name": "shape",
"description": "{ backdrop?: func<br>&#124;&nbsp;object, docked?: func<br>&#124;&nbsp;object, paper?: func<br>&#124;&nbsp;object, root?: func<br>&#124;&nbsp;object, swipeArea?: func<br>&#124;&nbsp;object, transition?: func<br>&#124;&nbsp;object }"
},
"default": "{}"
},
"slots": {
"type": {
"name": "shape",
"description": "{ backdrop?: elementType, docked?: elementType, paper?: elementType, root?: elementType, swipeArea?: elementType, transition?: elementType }"
},
"default": "{}"
},
"SwipeAreaProps": {
"type": { "name": "object" },
"deprecated": true,
"deprecationInfo": "use the <code>slotProps.swipeArea</code> prop instead. This prop will be removed in v7. See <a href=\"https://mui.com/material-ui/migration/migrating-from-deprecated-apis/\">Migrating from deprecated APIs</a> for more details."
},
"swipeAreaWidth": { "type": { "name": "number" }, "default": "20" },
"transitionDuration": {
"type": {
Expand All @@ -45,6 +63,14 @@
"import SwipeableDrawer from '@mui/material/SwipeableDrawer';",
"import { SwipeableDrawer } from '@mui/material';"
],
"slots": [
{
"name": "swipeArea",
"description": "The component used for the swipeArea slot.",
"default": "div",
"class": null
}
],
"classes": [
{
"key": "anchorBottom",
Expand Down
21 changes: 10 additions & 11 deletions docs/translations/api-docs/drawer/drawer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
"SlideProps": {
"description": "Props applied to the <a href=\"https://mui.com/material-ui/api/slide/\"><code>Slide</code></a> element."
},
"slotProps": { "description": "The props used for each slot inside." },
"slots": { "description": "The components used for each slot inside." },
"sx": {
"description": "The system prop that allows defining system overrides as well as additional CSS styles."
},
Expand Down Expand Up @@ -52,19 +54,10 @@
"nodeName": "the root element",
"conditions": "<code>anchor=\"top\"</code>"
},
"docked": {
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the root element",
"conditions": "<code>variant=\"permanent or persistent\"</code>"
},
"modal": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the Modal component"
},
"paper": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the Paper component"
},
"paperAnchorBottom": {
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the Paper component",
Expand Down Expand Up @@ -112,7 +105,13 @@
"nodeName": "the Paper component",
"conditions": "<code>anchor=\"top\"</code>",
"deprecationInfo": "Combine the <a href=\"/material-ui/api/drawer/#drawer-classes-MuiDrawer-anchorTop\">.MuiDrawer-anchorTop</a> and <a href=\"/material-ui/api/drawer/#drawer-classes-MuiDrawer-paper\">.MuiDrawer-paper</a> classes instead. <a href=\"/material-ui/migration/migrating-from-deprecated-apis/\">How to migrate</a>"
},
"root": { "description": "Styles applied to the root element." }
}
},
"slotDescriptions": {
"backdrop": "The component used for the Modal backdrop.",
"docked": "The component used for the root element when the variant is <code>permanent</code> or <code>persistent</code>.",
"paper": "The component used for the paper.",
"root": "The component used for the root when the variant is <code>temporary</code>.",
"transition": "The component used for the transition. <a href=\"https://mui.com/material-ui/transitions/#transitioncomponent-prop\">Follow this guide</a> to learn more about the requirements for this component."
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
"typeDescriptions": { "event": "The event source of the callback." }
},
"open": { "description": "If <code>true</code>, the component is shown." },
"slotProps": { "description": "The props used for each slot inside." },
"slots": { "description": "The components used for each slot inside." },
"SwipeAreaProps": {
"description": "The element is used to intercept the touch events on the edge."
},
Expand Down Expand Up @@ -122,5 +124,6 @@
"deprecationInfo": "Combine the <a href=\"/material-ui/api/drawer/#drawer-classes-MuiDrawer-anchorTop\">.MuiDrawer-anchorTop</a> and <a href=\"/material-ui/api/drawer/#drawer-classes-MuiDrawer-paper\">.MuiDrawer-paper</a> classes instead. <a href=\"/material-ui/migration/migrating-from-deprecated-apis/\">How to migrate</a>"
},
"root": { "description": "Styles applied to the root element." }
}
},
"slotDescriptions": { "swipeArea": "The component used for the swipeArea slot." }
}
2 changes: 1 addition & 1 deletion packages-internal/test-utils/src/describeConformance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ function testSlotPropsCallbackWithPropsAsOwnerState(
const { queryByTestId } = await render(
React.cloneElement(element, { slotProps, className: 'custom' }),
);
const slotComponent = queryByTestId('custom');
const slotComponent = queryByTestId('custom', { exact: false });
expect(slotComponent).not.to.equal(null);
});
});
Expand Down
2 changes: 2 additions & 0 deletions packages/mui-codemod/src/deprecations/all/deprecations-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import transformSnackbarProps from '../snackbar-props';
import transformSliderClasses from '../slider-classes';
import transformerTabsProps from '../tabs-props';
import transformerTabsClasses from '../tabs-classes';
import transformDrawerProps from '../drawer-props';

/**
* @param {import('jscodeshift').FileInfo} file
Expand Down Expand Up @@ -84,6 +85,7 @@ export default function deprecationsAll(file, api, options) {
file.source = transformSliderClasses(file, api, options);
file.source = transformerTabsProps(file, api, options);
file.source = transformerTabsClasses(file, api, options);
file.source = transformDrawerProps(file, api, options);

return file.source;
}
Loading