A drawer component for React.
ensure scroll gets re-enabled after closing (#67)
Emil Kowalski0d1ded7696a0
diff --git a/src/index.tsx b/src/index.tsxindex 53275e4..d273802 100644--- a/src/index.tsx+++ b/src/index.tsx@@ -128,7 +128,6 @@ function Root({defaultProp: defaultOpen,onChange: onOpenChange,});- const [isFullyClosed, setIsFullyClosed] = React.useState(true);const [isDragging, setIsDragging] = React.useState(false);const [isAnimating, setIsAnimating] = React.useState(true);const overlayRef = React.useRef<HTMLDivElement>(null);@@ -151,7 +150,7 @@ function Root({isDisabled: !isOpen || isDragging || isAnimating,});- usePositionFixed({ isOpen, isFullyClosed });+ usePositionFixed({ isOpen });function getScale() {return (window.innerWidth - WINDOW_TOP_OFFSET) / window.innerWidth;@@ -333,20 +332,6 @@ function Root({return () => window.visualViewport.removeEventListener('resize', onVisualViewportChange);}, []);- React.useEffect(() => {- if (isOpen) {- setIsFullyClosed(false);- }-- if (!isOpen) {- let id = setTimeout(() => {- setIsFullyClosed(true);- }, 300);-- return () => clearTimeout(id);- }- }, [isOpen, isAnimating]);-function closeDrawer() {if (!dismissible) return;drawerRef.current.setAttribute('vaul-closed-by-dragging', 'true');diff --git a/src/use-position-fixed.ts b/src/use-position-fixed.tsindex 79c5a95..7a51cc1 100644--- a/src/use-position-fixed.ts+++ b/src/use-position-fixed.ts@@ -3,7 +3,7 @@ import { isIOS } from './use-prevent-scroll';let previousBodyPosition = null;-export function usePositionFixed({ isOpen, isFullyClosed }: { isOpen: boolean; isFullyClosed: boolean }) {+export function usePositionFixed({ isOpen }: { isOpen: boolean }) {const scrollPos = React.useRef(0);function setPositionFixed() {@@ -74,11 +74,11 @@ export function usePositionFixed({ isOpen, isFullyClosed }: { isOpen: boolean; iReact.useEffect(() => {if (!isIOS()) return;- // This is needed to force Safari toolbar to show **before** the drawer starts animating to prevent a gnarly shift from happenning+ // This is needed to force Safari toolbar to show **before** the drawer starts animating to prevent a gnarly shift from happeningif (isOpen) {setPositionFixed();- } else if (isFullyClosed) {+ } else {restorePositionSetting();}- }, [isOpen, isFullyClosed]);+ }, [isOpen]);}