From c93d2ae190f784d1ca207d7f1a7e317b4b3ac5ef Mon Sep 17 00:00:00 2001 From: ZeeshanTamboli Date: Tue, 24 Sep 2024 10:56:37 +0530 Subject: [PATCH 1/2] Remove unnecessary manager prop on Modal --- packages/mui-material/src/Modal/useModal.ts | 8 +++----- packages/mui-material/src/Portal/Portal.types.ts | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/mui-material/src/Modal/useModal.ts b/packages/mui-material/src/Modal/useModal.ts index 5321d2f66ea75b..c1e242be6ff90f 100644 --- a/packages/mui-material/src/Modal/useModal.ts +++ b/packages/mui-material/src/Modal/useModal.ts @@ -26,7 +26,7 @@ function getHasTransition(children: UseModalParameters['children']) { // A modal manager used to track and manage the state of open Modals. // Modals don't open on the server so this won't conflict with concurrent requests. -const defaultManager = new ModalManager(); +const manager = new ModalManager(); /** * * Demos: @@ -42,8 +42,6 @@ function useModal(parameters: UseModalParameters): UseModalReturnValue { container, disableEscapeKeyDown = false, disableScrollLock = false, - // @ts-ignore internal logic - Base UI supports the manager as a prop too - manager = defaultManager, closeAfterTransition = false, onTransitionEnter, onTransitionExited, @@ -93,7 +91,7 @@ function useModal(parameters: UseModalParameters): UseModalReturnValue { } }); - const isTopModal = React.useCallback(() => manager.isTopModal(getModal()), [manager]); + const isTopModal = () => manager.isTopModal(getModal()); const handlePortalRef = useEventCallback((node: HTMLElement) => { mountNodeRef.current = node; @@ -111,7 +109,7 @@ function useModal(parameters: UseModalParameters): UseModalReturnValue { const handleClose = React.useCallback(() => { manager.remove(getModal(), ariaHiddenProp); - }, [ariaHiddenProp, manager]); + }, [ariaHiddenProp]); React.useEffect(() => { return () => { diff --git a/packages/mui-material/src/Portal/Portal.types.ts b/packages/mui-material/src/Portal/Portal.types.ts index 8e5717db2742bf..959d1b15b7af41 100644 --- a/packages/mui-material/src/Portal/Portal.types.ts +++ b/packages/mui-material/src/Portal/Portal.types.ts @@ -15,7 +15,7 @@ export interface PortalProps { * By default, it uses the body of the top-level document object, * so it's simply `document.body` most of the time. */ - container?: Element | (() => Element | null) | null; + container?: HTMLElement | (() => HTMLElement | null) | null; /** * The `children` will be under the DOM hierarchy of the parent component. * @default false From 500ed9063baad4f9bfbf033150610c8d8e986db9 Mon Sep 17 00:00:00 2001 From: ZeeshanTamboli Date: Tue, 24 Sep 2024 11:14:04 +0530 Subject: [PATCH 2/2] revert container type and assert type --- packages/mui-material/src/Modal/useModal.ts | 2 +- packages/mui-material/src/Portal/Portal.types.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/mui-material/src/Modal/useModal.ts b/packages/mui-material/src/Modal/useModal.ts index c1e242be6ff90f..9aca8a03c46a18 100644 --- a/packages/mui-material/src/Modal/useModal.ts +++ b/packages/mui-material/src/Modal/useModal.ts @@ -83,7 +83,7 @@ function useModal(parameters: UseModalParameters): UseModalReturnValue { const handleOpen = useEventCallback(() => { const resolvedContainer = getContainer(container) || getDoc().body; - manager.add(getModal(), resolvedContainer); + manager.add(getModal(), resolvedContainer as HTMLElement); // The element was already mounted. if (modalRef.current) { diff --git a/packages/mui-material/src/Portal/Portal.types.ts b/packages/mui-material/src/Portal/Portal.types.ts index 959d1b15b7af41..8e5717db2742bf 100644 --- a/packages/mui-material/src/Portal/Portal.types.ts +++ b/packages/mui-material/src/Portal/Portal.types.ts @@ -15,7 +15,7 @@ export interface PortalProps { * By default, it uses the body of the top-level document object, * so it's simply `document.body` most of the time. */ - container?: HTMLElement | (() => HTMLElement | null) | null; + container?: Element | (() => Element | null) | null; /** * The `children` will be under the DOM hierarchy of the parent component. * @default false