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
Changes from 4 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
4 changes: 4 additions & 0 deletions docs/data/material/guides/composition/composition.md
Original file line number Diff line number Diff line change
@@ -65,6 +65,10 @@ If you added another `className` via the `slotProps` prop on the Custom Tooltip
The popper slot in the original example would now have both classes applied to it, in addition to any others that may be present: `"[…] custom-tooltip-popper foo"`.
:::

:::info
`style` object are shallow merged rather than replacing one another. The style keys from the first argument have higher priority.
:::

## Component prop

Material UI allows you to change the root element that will be rendered via a prop called `component`.
52 changes: 52 additions & 0 deletions packages/mui-material/src/utils/mergeSlotProps.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import * as React from 'react';
import { expect } from 'chai';

import mergeSlotProps from './mergeSlotProps';

type OwnerState = {
className: string;
'aria-label'?: string;
style?: React.CSSProperties;
};

describe('utils/index.js', () => {
@@ -21,6 +23,27 @@ describe('utils/index.js', () => {
});
});

it('merge styles', () => {
expect(
mergeSlotProps<{ style: React.CSSProperties }>(
{ style: { color: 'red' } },
{ style: { backgroundColor: 'blue' } },
),
).to.deep.equal({
style: { color: 'red', backgroundColor: 'blue' },
});

// external styles should override
expect(
mergeSlotProps<{ style: React.CSSProperties }>(
{ style: { backgroundColor: 'red' } },
{ style: { backgroundColor: 'blue' } },
),
).to.deep.equal({
style: { backgroundColor: 'red' },
});
});

it('external slot props should override', () => {
expect(
mergeSlotProps<OwnerState>(
@@ -78,6 +101,35 @@ describe('utils/index.js', () => {
});
});

it('merge styles for callbacks', () => {
expect(
mergeSlotProps(
() => ({
style: { color: 'red' },
}),
() => ({
style: { backgroundColor: 'blue' },
}),
)(),
).to.deep.equal({
style: { color: 'red', backgroundColor: 'blue' },
});

// external styles should override
expect(
mergeSlotProps(
() => ({
style: { backgroundColor: 'red' },
}),
() => ({
style: { backgroundColor: 'blue' },
}),
)(),
).to.deep.equal({
style: { backgroundColor: 'red' },
});
});

it('external callback should be called with default slot props', () => {
expect(
mergeSlotProps<(ownerState: OwnerState) => OwnerState>(
8 changes: 8 additions & 0 deletions packages/mui-material/src/utils/mergeSlotProps.ts
Original file line number Diff line number Diff line change
@@ -28,6 +28,10 @@ export default function mergeSlotProps<
...defaultSlotPropsValue,
...externalSlotPropsValue,
...(!!className && { className }),
...(defaultSlotPropsValue?.style &&
externalSlotPropsValue?.style && {
style: { ...defaultSlotPropsValue.style, ...externalSlotPropsValue.style },
}),
};
}) as U;
}
@@ -39,5 +43,9 @@ export default function mergeSlotProps<
...defaultSlotProps,
...externalSlotProps,
...(!!className && { className }),
...((defaultSlotProps as Record<string, any>)?.style &&
externalSlotProps?.style && {
style: { ...(defaultSlotProps as Record<string, any>).style, ...externalSlotProps.style },
}),
} as U;
}