Skip to content

Commit f200ad0

Browse files
committed
feat: add skipInitialTransition to make skipping opt-in
1 parent 0871617 commit f200ad0

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,12 @@ Fired on: `CLOSE`.
205205
206206
The `yin` to `onSpringStart`'s `yang`. It has the same characteristics. Including `async/await` and Promise support for delaying a transition. For `CLOSE` it gives you a hook into the step right after it has cleaned up everything after itself, and right before it unmounts itself. This can be useful if you have some logic that needs to perform some work before it's safe to unmount.
207207
208+
### skipInitialTransition
209+
210+
Type: `boolean`
211+
212+
By default the initial open state is always transitioned to using an spring animation. Set `skipInitialTransition` to `true` and the initial `open` state will render as if it were the default state. Useful to avoid scenarios where the opening transition would be distracting.
213+
208214
## ref
209215
210216
Methods available when setting a `ref` on the sheet:

pages/fixtures/scrollable.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ const ScrollableFixturePage: NextPage<GetStaticProps> = ({
8585
<SnapMarker style={{ top: '75vh', ['--size' as any]: '0.5vh' }} />
8686
<BottomSheet
8787
open
88+
skipInitialTransition
8889
sibling={<CloseExample className="z-10" />}
8990
ref={sheetRef}
9091
initialFocusRef={focusRef}

src/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export type { RefHandles as BottomSheetRef } from './types'
99

1010
// Because SSR is annoying to deal with, and all the million complaints about window, navigator and dom elenents!
1111
export const BottomSheet = forwardRef<RefHandles, Props>(function BottomSheet(
12-
{ onSpringStart, onSpringEnd, ...props },
12+
{ onSpringStart, onSpringEnd, skipInitialTransition, ...props },
1313
ref
1414
) {
1515
// Mounted state, helps SSR but also ensures you can't tab into the sheet while it's closed, or nav there in a screen reader
@@ -23,7 +23,7 @@ export const BottomSheet = forwardRef<RefHandles, Props>(function BottomSheet(
2323
// It's only when initialState and props.open is mismatching that a intial transition should happen
2424
// If they match then transitions will only happen when a user interaction or resize event happen.
2525
const initialStateRef = useRef<'OPEN' | 'CLOSED'>(
26-
props.open ? 'OPEN' : 'CLOSED'
26+
skipInitialTransition && props.open ? 'OPEN' : 'CLOSED'
2727
)
2828

2929
// Using layout effect to support cases where the bottom sheet have to appear already open, no transition

src/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ export type Props = {
107107

108108
/* Configures body-scroll-lock to reserve scrollbar gap by setting padding on <body>, clears when closing the bottom sheet. on by default iff blocking=true */
109109
reserveScrollBarGap?: boolean
110+
111+
/* Open immediatly instead of initially animating from a closed => open state, useful if the bottom sheet is visible by default and the animation would be distracting */
112+
skipInitialTransition?: boolean
110113
} & Omit<React.PropsWithoutRef<JSX.IntrinsicElements['div']>, 'children'>
111114

112115
export interface RefHandles {

0 commit comments

Comments
 (0)