Skip to content

Commit

Permalink
Fix: Ensure drawer opens at the specified active snap point on initia…
Browse files Browse the repository at this point in the history
…l 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
  • Loading branch information
KhalafAbdi authored Oct 13, 2024
1 parent 1a8d000 commit e3ba34d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface DrawerContextValue {
keyboardIsOpen: React.MutableRefObject<boolean>;
snapPointsOffset: number[] | null;
snapPoints?: (number | string)[] | null;
activeSnapPointIndex?: number;
modal: boolean;
shouldFade: boolean;
activeSnapPoint?: number | string | null;
Expand Down
4 changes: 3 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,7 @@ export function Root({
keyboardIsOpen,
modal,
snapPointsOffset,
activeSnapPointIndex,

Check failure on line 772 in src/index.tsx

View workflow job for this annotation

GitHub Actions / test

Type 'number | null' is not assignable to type 'number | undefined'.
direction,
shouldScaleBackground,
setBackgroundColorOnScale,
Expand Down Expand Up @@ -824,6 +825,7 @@ export const Content = React.forwardRef<HTMLDivElement, ContentProps>(function (
onDrag,
keyboardIsOpen,
snapPointsOffset,
activeSnapPointIndex,
modal,
isOpen,
direction,
Expand Down Expand Up @@ -891,7 +893,7 @@ export const Content = React.forwardRef<HTMLDivElement, ContentProps>(function (
style={
snapPointsOffset && snapPointsOffset.length > 0
? ({
'--snap-point-height': `${snapPointsOffset[0]!}px`,
'--snap-point-height': `${snapPointsOffset[activeSnapPointIndex ?? 0]!}px`,
...style,
} as React.CSSProperties)
: style
Expand Down

0 comments on commit e3ba34d

Please sign in to comment.