An open source design system that's fully customizable and agent ready
TypeScript
fix(core): a tap inside the Bottom Sheet is a tap, and the sheet leaves on an exit curve (#5326)
Xinzi Zhouf30c60415d4e
diff --git a/.changeset/bottom-sheet-tap-and-exit.md b/.changeset/bottom-sheet-tap-and-exit.mdnew file mode 100644index 0000000000..bb796519bd--- /dev/null+++ b/.changeset/bottom-sheet-tap-and-exit.md@@ -0,0 +1,15 @@+---+'@astryxdesign/core': patch+---++[fix] BottomSheet: a tap inside the sheet is a tap, and the sheet leaves on an exit curve.++Two defects, both of which read as "the sheet closes with no animation" — reported against the touch DateInput picker, which is a Bottom Sheet.++**A tap inside the sheet started a one-pixel drag.** The sheet body carries the pull-to-dismiss handlers, and they promoted to a sheet drag on _any_ downward movement. A finger is never still, so the pixel or two a tap drifts began a drag — and a live drag suppresses the panel's transition, correctly, because a dragged sheet must track the finger rather than lag it. The close that the tap triggered landed inside that window, so the sheet jumped to its closed position with no transition. Tapping the picker's Save button hit this every time; tapping the scrim never did, because the scrim is the dialog itself and arms no gesture. Promotion now needs 8px of travel — the conventional tap slop, well under what a deliberate pull covers in its first frames — in both the pointer and touch paths. The gesture's transition suppression is also scoped to a sheet that is open, so it cannot straddle an exit.++**The exit ran on the entrance's curve.** `--ease-standard` is `cubic-bezier(0.24, 1, 0.4, 1)`, a decelerate curve: it spends its speed immediately and coasts. Right for an entrance, wrong for an exit. Measured on device (iPhone, real Safari), a scrim tap put the sheet half off-screen in 59ms of the 410ms transition and 90% off in 163ms, with the dim gone before it — so the close was over before the eye could follow it. The closing state now carries an accelerating curve of its own, `cubic-bezier(0.3, 0, 0.6, 0.6)`: away from rest, gathering speed, quickest as it leaves the screen, and moving within ~50ms so it reads as one departure rather than a hesitation and a snap. Only the curve changes — the exit keeps `--duration-medium`, the entrance's band, which is what keeps it legible under a theme that scales the motion scale down (neutral's medium is 300ms against the base 410ms).++The scrim leaves with the sheet: while closing, the dim runs `linear` rather than the decelerate token. A fade covers no distance, so front-loading its progress just ends it early — the reasoning the touch date picker's surface swap already carries. `BottomSheetSwitcher` gets the same treatment when its flow closes; a handoff between two sheets is not a close and is unchanged.++@imdreamrunnerdiff --git a/packages/core/src/BottomSheet/BottomSheet.tsx b/packages/core/src/BottomSheet/BottomSheet.tsxindex f73a3de3f6..efedb1b785 100644--- a/packages/core/src/BottomSheet/BottomSheet.tsx+++ b/packages/core/src/BottomSheet/BottomSheet.tsx@@ -93,6 +93,20 @@ const styles = stylex.create({},},},+ /**+ * The dim leaves with the sheet, on a curve that matches.+ *+ * A fade covers no distance, so the decelerate token front-loads its+ * progress and simply ends it early: `--ease-standard` puts the scrim at 90%+ * faded in 163ms of a 410ms close, leaving an undimmed page under a sheet+ * that is still sliding across it. `linear` spends the duration it is given.+ * Same reasoning the touch date picker's surface swap already carries.+ */+ scrimClosing: {+ '::backdrop': {+ transitionTimingFunction: 'linear',+ },+ },positioner: {position: 'absolute',insetInline: 0,@@ -327,6 +341,7 @@ function StandaloneBottomSheet({styles.dialog,shouldPresent && styles.dialogOpen,hasScrim && styles.scrim,+ hasScrim && !isOpen && isPresented && styles.scrimClosing,!hasScrim && styles.dialogNonModal,)}ref={dialogRef}diff --git a/packages/core/src/BottomSheet/BottomSheetPanel.test.tsx b/packages/core/src/BottomSheet/BottomSheetPanel.test.tsxindex 8d8c88bf83..555e49e60c 100644--- a/packages/core/src/BottomSheet/BottomSheetPanel.test.tsx+++ b/packages/core/src/BottomSheet/BottomSheetPanel.test.tsx@@ -328,4 +328,70 @@ describe('BottomSheetPanel', () => {"backgroundColor: colorVars['--color-background-surface']",);});++ /**+ * The exit is not the entrance played backwards.+ *+ * `--ease-standard` is a decelerate curve: on it the sheet was half gone in+ * 59ms of a 410ms transition and 90% gone in 163ms, so the close was over+ * before it could be seen. The closing state therefore carries its own+ * accelerating curve, and only the closing state does.+ */+ it('closes on an accelerating curve of its own, not the entrance timing', () => {+ const declarationsFor = (element: HTMLElement) => {+ const classes = new Set(element.className.split(/\s+/));+ const out: string[] = [];+ for (const styleSheet of Array.from(document.styleSheets)) {+ let rules: CSSRuleList;+ try {+ rules = styleSheet.cssRules;+ } catch {+ continue;+ }+ for (const rule of Array.from(rules)) {+ const selector = (rule as CSSStyleRule).selectorText;+ const owner = selector?.match(/^\.([\w-]+)/)?.[1];+ if (owner != null && classes.has(owner)) {+ out.push(rule.cssText);+ }+ }+ }+ return out.join('\n');+ };++ const {container: closing} = render(+ <BottomSheetPanel+ state={{kind: 'exiting'}}+ height="hug"+ onDismiss={() => {}}+ onScrimOpacity={() => {}}>+ Panel content+ </BottomSheetPanel>,+ );+ const closingRules = declarationsFor(+ closing.querySelector('.astryx-bottom-sheet') as HTMLElement,+ );+ // An accelerating curve: no vertical rise at the start (y1 = 0), so the+ // travel lands inside the duration instead of ahead of it.+ expect(closingRules).toContain(+ 'transition-timing-function: cubic-bezier(.3,0,.6,.6)',+ );++ const {container: resting} = render(+ <BottomSheetPanel+ state={{kind: 'open', entering: false}}+ height="hug"+ onDismiss={() => {}}+ onScrimOpacity={() => {}}>+ Panel content+ </BottomSheetPanel>,+ );+ const restingRules = declarationsFor(+ resting.querySelector('.astryx-bottom-sheet') as HTMLElement,+ );+ expect(restingRules).toContain(+ 'transition-timing-function: var(--ease-standard)',+ );+ expect(restingRules).not.toContain('cubic-bezier(.3,0,.6,.6)');+ });});diff --git a/packages/core/src/BottomSheet/BottomSheetPanel.tsx b/packages/core/src/BottomSheet/BottomSheetPanel.tsxindex 115bc1548b..836f72c7c5 100644--- a/packages/core/src/BottomSheet/BottomSheetPanel.tsx+++ b/packages/core/src/BottomSheet/BottomSheetPanel.tsx@@ -149,8 +149,27 @@ const styles = stylex.create({transitionDuration: '0.01s',},},+ /**+ * The exit is its own motion, not the entrance played backwards.+ *+ * `--ease-standard` is `cubic-bezier(0.24, 1, 0.4, 1)`, a decelerate curve:+ * it spends its speed immediately and coasts. That is right for an entrance,+ * where the sheet arrives fast and settles, and wrong for an exit. Measured+ * on device, it put the sheet half off-screen in 59ms of a 410ms close and+ * 90% off in 163ms -- the travel is over before the eye has followed it, and+ * the rest of the duration moves pixels already below the fold.+ *+ * An exit accelerates instead: away from rest, gathering speed, quickest as+ * it leaves the screen. The curve is deliberately gentle rather than a hard+ * `ease-in` -- it is moving within ~50ms, so the close reads as one+ * departure rather than a hesitation and a snap. The duration is the+ * entrance's own band, so only the curve differs between the two+ * directions; a shorter band leaves too little visible travel once a theme+ * scales the motion scale down (neutral's medium is 300ms against 410ms).+ */sheetClosing: {transform: 'translateY(100%)',+ transitionTimingFunction: 'cubic-bezier(0.3, 0, 0.6, 0.6)',},sheetFading: {opacity: 0,diff --git a/packages/core/src/BottomSheet/BottomSheetSwitcher.tsx b/packages/core/src/BottomSheet/BottomSheetSwitcher.tsxindex b3cefa68da..2e9fff96fa 100644--- a/packages/core/src/BottomSheet/BottomSheetSwitcher.tsx+++ b/packages/core/src/BottomSheet/BottomSheetSwitcher.tsx@@ -103,6 +103,14 @@ const styles = stylex.create({},},},+ // The flow's dim leaves with its last panel. Same rule, same reasoning, as+ // a standalone sheet's -- see `scrimClosing` in BottomSheet.tsx. A handoff+ // between two sheets is not a close, and keeps the entrance curve.+ scrimClosing: {+ '::backdrop': {+ transitionTimingFunction: 'linear',+ },+ },});type RetainedSheetPhase = 'covered' | 'aligning' | 'fading' | 'exiting';@@ -593,6 +601,7 @@ export function BottomSheetSwitcher({styles.dialog,isFlowVisible && styles.dialogOpen,hasScrim && styles.scrim,+ hasScrim && isFlowVisible && activeSheet == null && styles.scrimClosing,!hasScrim && styles.dialogNonModal,xstyle,);diff --git a/packages/core/src/BottomSheet/useSheetGestures.test.ts b/packages/core/src/BottomSheet/useSheetGestures.test.tsindex 0d500b6bb5..6a496769bb 100644--- a/packages/core/src/BottomSheet/useSheetGestures.test.ts+++ b/packages/core/src/BottomSheet/useSheetGestures.test.ts@@ -530,6 +530,33 @@ describe('useSheetGestures', () => {expect(hook.result.current.dragOffset).toBe(40);});+ /**+ * A finger is never still. Tapping a control inside the sheet drifts a+ * pixel or two, and with no slop that drift promoted to a sheet drag —+ * which wrote `transition: none` onto the panel across the release, so the+ * close the tap triggered cut instead of animating. That is the "the sheet+ * closes with no animation" report: only on a tap, and only on a tap+ * inside the sheet (the scrim never arms a drag).+ */+ it('treats a few pixels of finger drift as a tap, not a drag', () => {+ const {hook} = setup({snapHeights: () => [200]});+ const body = makeBody(0); // at the top, where a pull-down would promote+ bodyDown(hook, 0, 0, body);+ bodyMove(hook, 3, 40, body); // the drift of a finger tapping a button+ expect(hook.result.current.isDragging).toBe(false);+ // and nothing suppressed the panel's transition, so a close that lands+ // now still animates+ expect(hook.result.current.contentProps.style.transition).toBeUndefined();+ });++ it('still promotes once the pull passes the tap slop', () => {+ const {hook} = setup({snapHeights: () => [200]});+ const body = makeBody(0);+ bodyDown(hook, 0, 0, body);+ bodyMove(hook, 9, 40, body); // just past the 8px slop+ expect(hook.result.current.isDragging).toBe(true);+ });+it('does not hijack scrolling when the body is scrolled down', () => {const {hook} = setup({snapHeights: () => [200]});const body = makeBody(120); // scrolled, not at the topdiff --git a/packages/core/src/BottomSheet/useSheetGestures.ts b/packages/core/src/BottomSheet/useSheetGestures.tsindex 6eab9f3f8a..e4aee9a088 100644--- a/packages/core/src/BottomSheet/useSheetGestures.ts+++ b/packages/core/src/BottomSheet/useSheetGestures.ts@@ -118,6 +118,20 @@ const OVERSCROLL_MAX = 48;// the scroll, large enough that a swipe merely coming to rest on the last pixel// doesn't start a drag on jitter.const CONTENT_END_HANDOFF_SLOP = 4;+// How far a finger resting on the body must travel before the pull becomes a+// sheet drag rather than a tap.+//+// This used to be zero: any downward movement promoted. A finger is never+// still, so tapping a control inside the sheet drifted a pixel or two and+// started a drag -- which suppresses the panel's transition, correctly, for as+// long as the sheet is tracking the finger. The close that the tap triggered+// then landed inside that window and cut instead of animating. A deliberate+// pull was unaffected; only a tap, and only a tap inside the sheet, since the+// scrim is outside the body and arms nothing.+//+// 8px is the conventional tap slop, a shade over iOS's own recognizer, and+// well under what a real pull covers in its first frames.+const DRAG_PROMOTION_SLOP = 8;// Short haptic tick on detent settle where supported. iOS Safari doesn't// expose navigator.vibrate, so this is a no-op there; skipped under@@ -1140,7 +1154,7 @@ export function useSheetGestures({return;}const delta = event.clientY - armed.startCoord;- if (delta > 0 && armed.scroller.scrollTop <= 0) {+ if (delta > DRAG_PROMOTION_SLOP && armed.scroller.scrollTop <= 0) {// Downward pull at the top: promote to a sheet drag, anchored at the// original pointer-down position so the pull distance carries over.armedBodyRef.current = null;@@ -1302,8 +1316,10 @@ export function useSheetGestures({// no longer scroll that way: at the top, a downward pull (delta > 0)// collapses; at the bottom, an upward pull (delta < 0) expands. The// opposite direction is a real scroll, so disarm and let it through.- const pullDownAtTop = armed.top && delta > 0 && atTop(scroller);- const pullUpAtBottom = armed.bottom && delta < 0 && atBottom(scroller);+ const pullDownAtTop =+ armed.top && delta > DRAG_PROMOTION_SLOP && atTop(scroller);+ const pullUpAtBottom =+ armed.bottom && delta < -DRAG_PROMOTION_SLOP && atBottom(scroller);if (pullDownAtTop || pullUpAtBottom) {event.preventDefault();touchDragRef.current = null;@@ -1433,15 +1449,19 @@ export function useSheetGestures({style: {transform:activeOffset !== 0 ? `translateY(${activeOffset}px)` : undefined,+ // Gated on the sheet being up: suppression must not outlive the sheet+ // it was suppressing for. The host swaps the panel to its closing+ // state in whatever frame the dismissal lands, and a stale `none`+ // would apply to that transform too, cutting the exit.transition:- isDragging || isScrollAreaReconciling || reducedMotion+ isOpen && (isDragging || isScrollAreaReconciling || reducedMotion)? 'none': undefined,touchAction: 'none',overscrollBehavior: 'contain',},}),- [activeOffset, isDragging, isScrollAreaReconciling, reducedMotion],+ [activeOffset, isDragging, isOpen, isScrollAreaReconciling, reducedMotion],);const handleProps = useMemo<SheetHandleProps>(