Skip to content

[@mantine/core] Modal: Keep scroll lock during exit transition - #9559

Open
rishabhx29 wants to merge 1 commit into
mantinedev:masterfrom
rishabhx29:fix/modal-exit-duration-scroll-lock
Open

rishabhx29 wants to merge 1 commit into
mantinedev:masterfrom
rishabhx29:fix/modal-exit-duration-scroll-lock

Conversation

@rishabhx29

Copy link
Copy Markdown
Contributor

Problem

useModal passes only transitionProps.duration to useLockScroll:

const transitionDuration =
  typeof transitionProps?.duration === 'number' ? transitionProps.duration : 200;

const shouldLockScroll = useLockScroll({ opened, transitionDuration });

Transition supports a separate exitDuration (falling back to duration). When the exit animation is longer than the enter animation, RemoveScroll is disabled after duration, so the page becomes scrollable while the modal is still animating out.

Reproduction

A focused hook test with transitionProps={{ duration: 0, exitDuration: 500 }}:

rerender(<LockProbe opened={false} />);
act(() => jest.advanceTimersByTime(100));
expect(screen.getByTestId('locked')).toHaveTextContent('true');

On unfixed master, the lock is already released after 100 ms (Received: false). With the fix it stays locked until the 500 ms exit finishes.

Solution

Use transitionProps.exitDuration when it is a number, falling back to duration:

const exitDuration =
  typeof transitionProps?.exitDuration === 'number'
    ? transitionProps.exitDuration
    : transitionDuration;

const shouldLockScroll = useLockScroll({ opened, transitionDuration: exitDuration });

Enter behavior is unchanged — the lock is enabled immediately on open.

Tests

New use-modal.test.tsx using fake timers. Passes with the fix, fails on unfixed master.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant