From e3ba34d6cf6d6937b025a90eeb3b4fcd8bbcba37 Mon Sep 17 00:00:00 2001 From: Khalaf <59578087+KhalafAbdi@users.noreply.github.com> Date: Sun, 13 Oct 2024 12:39:41 +0200 Subject: [PATCH] Fix: Ensure drawer opens at the specified active snap point on initial render (#473) * add activeSnapPointIndex to context type * passing activeSnapPointIndex to context * getting and using activeSnapPointIndex from context * Added back spaces * added back space * activeSnapPointIndex fallback --- src/context.ts | 1 + src/index.tsx | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/context.ts b/src/context.ts index 4f8742c..6678d64 100644 --- a/src/context.ts +++ b/src/context.ts @@ -16,6 +16,7 @@ interface DrawerContextValue { keyboardIsOpen: React.MutableRefObject; snapPointsOffset: number[] | null; snapPoints?: (number | string)[] | null; + activeSnapPointIndex?: number; modal: boolean; shouldFade: boolean; activeSnapPoint?: number | string | null; diff --git a/src/index.tsx b/src/index.tsx index 99179b6..e128e90 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -769,6 +769,7 @@ export function Root({ keyboardIsOpen, modal, snapPointsOffset, + activeSnapPointIndex, direction, shouldScaleBackground, setBackgroundColorOnScale, @@ -824,6 +825,7 @@ export const Content = React.forwardRef(function ( onDrag, keyboardIsOpen, snapPointsOffset, + activeSnapPointIndex, modal, isOpen, direction, @@ -891,7 +893,7 @@ export const Content = React.forwardRef(function ( style={ snapPointsOffset && snapPointsOffset.length > 0 ? ({ - '--snap-point-height': `${snapPointsOffset[0]!}px`, + '--snap-point-height': `${snapPointsOffset[activeSnapPointIndex ?? 0]!}px`, ...style, } as React.CSSProperties) : style