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] Allow useSlotProps to receive undefined elementType #35192

Merged
merged 5 commits into from Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/mui-base/src/utils/appendOwnerState.test.ts
Expand Up @@ -11,6 +11,15 @@ function CustomComponent() {
}

describe('appendOwnerState', () => {
describe('when the provided elementType is undefined', () => {
it('returns the provided existingProps without modification ', () => {
const existingProps = { className: 'foo' };
const actual = appendOwnerState(undefined, existingProps, ownerState);

expect(actual).to.equal(existingProps);
});
});

describe('when a DOM element is provided as elementType', () => {
it('returns the provided existingProps without modification ', () => {
const existingProps = { className: 'foo' };
Expand Down
6 changes: 3 additions & 3 deletions packages/mui-base/src/utils/appendOwnerState.ts
Expand Up @@ -29,7 +29,7 @@ export type AppendOwnerStateReturnType<
/**
* Appends the ownerState object to the props, merging with the existing one if necessary.
*
* @param elementType Type of the element that owns the `existingProps`. If the element is a DOM node, `ownerState` is not applied.
* @param elementType Type of the element that owns the `existingProps`. If the element is a DOM node or undefined, `ownerState` is not applied.
* @param otherProps Props of the element.
* @param ownerState
*/
Expand All @@ -38,11 +38,11 @@ export default function appendOwnerState<
OtherProps extends Record<string, any>,
OwnerState,
>(
elementType: ElementType,
elementType: ElementType | undefined,
otherProps: OtherProps,
ownerState: OwnerState,
): AppendOwnerStateReturnType<ElementType, OtherProps, OwnerState> {
if (isHostComponent(elementType)) {
if (elementType === undefined || isHostComponent(elementType)) {
return otherProps as AppendOwnerStateReturnType<ElementType, OtherProps, OwnerState>;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/mui-base/src/utils/useSlotProps.ts
Expand Up @@ -22,7 +22,7 @@ export type UseSlotPropsParameters<
/**
* The type of the component used in the slot.
*/
elementType: ElementType;
elementType: ElementType | undefined;
/**
* The `slotProps.*` of the unstyled component.
*/
Expand Down