A drawer component for React.
Dont run use-position-fixed hug when drawer is nested (#82)
Emil Kowalski0b335fd4f54d
diff --git a/src/index.tsx b/src/index.tsxindex dac341c..bea023a 100644--- a/src/index.tsx+++ b/src/index.tsx@@ -50,6 +50,7 @@ type DialogProps = {onRelease?(event: React.PointerEvent<HTMLDivElement>, open: boolean): void;experimentalSafariThemeAnimation?: boolean;modal?: boolean;+ nested?: boolean;onClose?: () => void;} & (WithFadeFromProps | WithoutFadeFromProps);@@ -63,6 +64,7 @@ function Root({onRelease: onReleaseProp,experimentalSafariThemeAnimation,snapPoints,+ nested,closeThreshold = CLOSE_THRESHOLD,scrollLockTimeout = SCROLL_LOCK_TIMEOUT,dismissible = true,@@ -118,7 +120,7 @@ function Root({isDisabled: !isOpen || isDragging || !modal || justReleased,});- usePositionFixed({ isOpen, modal });+ usePositionFixed({ isOpen, modal, nested });function getScale() {return (window.innerWidth - WINDOW_TOP_OFFSET) / window.innerWidth;@@ -703,6 +705,7 @@ function NestedRoot({ children, onDrag, onOpenChange }: DialogProps) {onClose={() => {onNestedOpenChange(false);}}+ nested={true}onOpenChange={(o) => {if (o) {onNestedOpenChange(o);diff --git a/src/use-position-fixed.ts b/src/use-position-fixed.tsindex 5c2dfa7..b264f6c 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: Record<string, string> | null = null;-export function usePositionFixed({ isOpen, modal }: { isOpen: boolean; modal: boolean }) {+export function usePositionFixed({ isOpen, modal, nested }: { isOpen: boolean; modal: boolean; nested: boolean }) {const scrollPos = React.useRef(0);function setPositionFixed() {@@ -73,7 +73,7 @@ export function usePositionFixed({ isOpen, modal }: { isOpen: boolean; modal: bo}, []);React.useEffect(() => {- if (!isIOS()) return;+ if (!isIOS() || nested) return;// This is needed to force Safari toolbar to show **before** the drawer starts animating to prevent a gnarly shift from happeningif (isOpen) {setPositionFixed();