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

[core][Modal] Remove unnecessary manager prop handling #43867

Merged
Changes from all 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
10 changes: 4 additions & 6 deletions packages/mui-material/src/Modal/useModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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,
Expand Down Expand Up @@ -85,15 +83,15 @@ function useModal(parameters: UseModalParameters): UseModalReturnValue {
const handleOpen = useEventCallback(() => {
const resolvedContainer = getContainer(container) || getDoc().body;

manager.add(getModal(), resolvedContainer);
manager.add(getModal(), resolvedContainer as HTMLElement);
Copy link
Member Author

@ZeeshanTamboli ZeeshanTamboli Sep 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to cast it because the container prop is typed as Element (see here), but the modal manager methods expect HTMLElement, which is correct. Also, document.body (the default container) is an HTMLElement. Changing the container type in Portal would be a breaking change, though we could also allow both Element and HTMLElement.


// The element was already mounted.
if (modalRef.current) {
handleMounted();
}
});

const isTopModal = React.useCallback(() => manager.isTopModal(getModal()), [manager]);
const isTopModal = () => manager.isTopModal(getModal());

const handlePortalRef = useEventCallback((node: HTMLElement) => {
mountNodeRef.current = node;
Expand All @@ -111,7 +109,7 @@ function useModal(parameters: UseModalParameters): UseModalReturnValue {

const handleClose = React.useCallback(() => {
manager.remove(getModal(), ariaHiddenProp);
}, [ariaHiddenProp, manager]);
}, [ariaHiddenProp]);

React.useEffect(() => {
return () => {
Expand Down
Loading