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

[base] Change the order of class names merged in useSlotProps #33383

Merged
merged 3 commits into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
11 changes: 4 additions & 7 deletions packages/mui-base/src/utils/mergeSlotProps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('mergeSlotProps', () => {
expect(merged.props.prop4).to.equal('internal');
});

it('joins all the class names', () => {
it('joins all the class names in order from internal to external', () => {
const getSlotProps = () => ({
className: 'internal',
});
Expand All @@ -67,12 +67,9 @@ describe('mergeSlotProps', () => {
className,
});

expect(merged.props.className).to.contain('class1');
expect(merged.props.className).to.contain('class2');
expect(merged.props.className).to.contain('internal');
expect(merged.props.className).to.contain('additional');
expect(merged.props.className).to.contain('externalForwarded');
expect(merged.props.className).to.contain('externalSlot');
expect(merged.props.className).to.equal(
'internal additional class1 class2 externalForwarded externalSlot',
);
});

it('merges the style props', () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/mui-base/src/utils/mergeSlotProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,11 @@ export default function mergeSlotProps<

const internalSlotProps = getSlotProps(eventHandlers);
const joinedClasses = clsx(
internalSlotProps?.className,
additionalProps?.className,
className,
externalForwardedProps?.className,
externalSlotProps?.className,
className,
additionalProps?.className,
internalSlotProps?.className,
);

const mergedStyle = {
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-base/src/utils/useSlotProps.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ describe('useSlotProps', () => {
// class names are concatenated
expect(result).to.haveOwnProperty(
'className',
'externalForwarded externalComponentsProps another-class yet-another-class additional internal',
'internal additional another-class yet-another-class externalForwarded externalComponentsProps',
);

// `data-test` from componentProps overrides the one from forwardedProps
Expand Down