From fc0f95909266c96a686dc04bb8a4f97bf1fe6b1c Mon Sep 17 00:00:00 2001 From: Levent Deniz Date: Fri, 18 Nov 2022 11:35:39 +0100 Subject: [PATCH 1/4] [Base] Allow useSlotProps to receive undefined elementType --- packages/mui-base/src/utils/appendOwnerState.ts | 4 ++-- packages/mui-base/src/utils/useSlotProps.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/mui-base/src/utils/appendOwnerState.ts b/packages/mui-base/src/utils/appendOwnerState.ts index 5ecbd67e6ff624..0950ac2ea9b0c7 100644 --- a/packages/mui-base/src/utils/appendOwnerState.ts +++ b/packages/mui-base/src/utils/appendOwnerState.ts @@ -38,11 +38,11 @@ export default function appendOwnerState< OtherProps extends Record, OwnerState, >( - elementType: ElementType, + elementType: ElementType | undefined, otherProps: OtherProps, ownerState: OwnerState, ): AppendOwnerStateReturnType { - if (isHostComponent(elementType)) { + if (elementType && isHostComponent(elementType)) { return otherProps as AppendOwnerStateReturnType; } diff --git a/packages/mui-base/src/utils/useSlotProps.ts b/packages/mui-base/src/utils/useSlotProps.ts index 9fae5f82c75954..7ec2e93501d47e 100644 --- a/packages/mui-base/src/utils/useSlotProps.ts +++ b/packages/mui-base/src/utils/useSlotProps.ts @@ -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. */ From 5b91218a7b903de91aec08efe1251bd33317a74d Mon Sep 17 00:00:00 2001 From: Levent Deniz Date: Fri, 18 Nov 2022 14:17:04 +0100 Subject: [PATCH 2/4] [Base] Fix condition and Add type change to the docBlock --- packages/mui-base/src/utils/appendOwnerState.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/mui-base/src/utils/appendOwnerState.ts b/packages/mui-base/src/utils/appendOwnerState.ts index 0950ac2ea9b0c7..1364a338f52d1f 100644 --- a/packages/mui-base/src/utils/appendOwnerState.ts +++ b/packages/mui-base/src/utils/appendOwnerState.ts @@ -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 undefined or a DOM node, `ownerState` is not applied. * @param otherProps Props of the element. * @param ownerState */ @@ -42,7 +42,7 @@ export default function appendOwnerState< otherProps: OtherProps, ownerState: OwnerState, ): AppendOwnerStateReturnType { - if (elementType && isHostComponent(elementType)) { + if (elementType === undefined || isHostComponent(elementType)) { return otherProps as AppendOwnerStateReturnType; } From 5cab38d7bd01231a6031a58b1128d58ae81263be Mon Sep 17 00:00:00 2001 From: Levent Deniz Date: Fri, 18 Nov 2022 14:17:19 +0100 Subject: [PATCH 3/4] [Base] Add test case for undefined elementType on appendOwnerState --- packages/mui-base/src/utils/appendOwnerState.test.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/mui-base/src/utils/appendOwnerState.test.ts b/packages/mui-base/src/utils/appendOwnerState.test.ts index f775075b503010..1b5ba88ec0170e 100644 --- a/packages/mui-base/src/utils/appendOwnerState.test.ts +++ b/packages/mui-base/src/utils/appendOwnerState.test.ts @@ -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' }; From e27e2294dee976543d6f4fd273419b0fe07e2aa0 Mon Sep 17 00:00:00 2001 From: Levent Deniz Date: Mon, 21 Nov 2022 11:33:46 +0100 Subject: [PATCH 4/4] [Base] Improve docBlock wording on appendOwnerState --- packages/mui-base/src/utils/appendOwnerState.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/mui-base/src/utils/appendOwnerState.ts b/packages/mui-base/src/utils/appendOwnerState.ts index 1364a338f52d1f..6731ada3d47cbf 100644 --- a/packages/mui-base/src/utils/appendOwnerState.ts +++ b/packages/mui-base/src/utils/appendOwnerState.ts @@ -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 undefined or 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 */