Skip to content

Commit

Permalink
[Base] Allow useSlotProps to receive undefined elementType (mui#35192)
Browse files Browse the repository at this point in the history
  • Loading branch information
leventdeniz authored and Daniel Rabe committed Nov 29, 2022
1 parent 828055e commit 02736ee
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
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

0 comments on commit 02736ee

Please sign in to comment.