diff --git a/src/use-position-fixed.ts b/src/use-position-fixed.ts index 4a6efc2..59bbcfb 100644 --- a/src/use-position-fixed.ts +++ b/src/use-position-fixed.ts @@ -109,6 +109,20 @@ export function usePositionFixed({ }; }, []); + React.useEffect(() => { + if (!modal) return; + + return () => { + if (typeof document === 'undefined') return; + + // Another drawer is opened, safe to ignore the execution + const hasDrawerOpened = !!document.querySelector('[data-vaul-drawer]'); + if (hasDrawerOpened) return; + + restorePositionSetting(); + }; + }, [modal, restorePositionSetting]); + React.useEffect(() => { if (nested || !hasBeenOpened) return; // This is needed to force Safari toolbar to show **before** the drawer starts animating to prevent a gnarly shift from happening diff --git a/test/src/app/page.tsx b/test/src/app/page.tsx index 0e99d34..17e6de1 100644 --- a/test/src/app/page.tsx +++ b/test/src/app/page.tsx @@ -14,7 +14,8 @@ export default function Page() { Non-dismissible Initial snap Controlled - Controlled + Default open + With redirect ); } diff --git a/test/src/app/with-redirect/long-page/page.tsx b/test/src/app/with-redirect/long-page/page.tsx new file mode 100644 index 0000000..729bab0 --- /dev/null +++ b/test/src/app/with-redirect/long-page/page.tsx @@ -0,0 +1,10 @@ +'use client'; + +export default function Page() { + return ( +
scroll down
+content only visible after scroll
+This route is only used to test the body reset position.
++ Go to{' '} + + another route + {' '} +
+