Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(core): a bottom-edge pull-up no longer hijacks a fully expanded Bottom Sheet (#5161)

Xinzi Zhou87046008b612
diff --git a/.changeset/bottom-sheet-scroll-drag-handoff.md b/.changeset/bottom-sheet-scroll-drag-handoff.md
new file mode 100644
index 0000000000..f95a948392
--- /dev/null
+++ b/.changeset/bottom-sheet-scroll-drag-handoff.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] BottomSheet: an upward pull at the bottom of scrolled content no longer hijacks the gesture when the sheet is already fully expanded. It used to hand off to a sheet drag with nowhere to expand to, producing a rubber-band the release threw straight back, and — because the handoff swallows the rest of the gesture — leaving the content unscrollable until the finger lifted, so dragging back down collapsed the sheet instead of scrolling. The bottom edge now hands off only when a taller detent exists.
+
+@imdreamrunner
diff --git a/packages/core/src/BottomSheet/useSheetGestures.test.ts b/packages/core/src/BottomSheet/useSheetGestures.test.ts
index 0e49162380..987f6c57bb 100644
--- a/packages/core/src/BottomSheet/useSheetGestures.test.ts
+++ b/packages/core/src/BottomSheet/useSheetGestures.test.ts
@@ -549,7 +549,7 @@ describe('useSheetGestures', () => {
expect(hook.result.current.isDragging).toBe(true);
});
- it('promotes a bottom pull-up (touch) into a sheet drag', () => {
+ it('promotes a bottom pull-up (touch) into a sheet drag that travels', () => {
const {hook} = setup({snapHeights: () => [200]});
// scrolled to the bottom: scrollTop + clientHeight === scrollHeight
const el = makeScroller({
@@ -559,11 +559,67 @@ describe('useSheetGestures', () => {
});
act(() => hook.result.current.sheetRef(el));
act(() => hook.result.current.bodyProps.ref(el));
+ // Settle at the lower detent first, so expanding has somewhere to go.
+ down(hook, 0, 0, el);
+ move(hook, 180, 700, el);
+ up(hook, 180, 1100, el);
+ expect(hook.result.current.settledOffset).toBe(200);
+
act(() => {
touch(el, 'touchstart', 300);
touch(el, 'touchmove', 250); // pull up
});
expect(hook.result.current.isDragging).toBe(true);
+ // The handoff is only worth taking if the sheet follows the finger:
+ // 50px of pull expands 50px toward the tallest detent.
+ expect(hook.result.current.dragOffset).toBe(150);
+ });
+
+ it('leaves a bottom pull-up with the scroller at the tallest detent', () => {
+ // Regression: the sheet is already fully expanded, so an upward pull has
+ // nowhere to expand to. Promoting it produced a rubber-band the release
+ // threw straight back, and stole the gesture from the scroller.
+ const {hook} = setup({snapHeights: () => [200]});
+ const el = makeScroller({
+ scrollTop: 600,
+ clientHeight: 200,
+ scrollHeight: 800,
+ });
+ act(() => hook.result.current.sheetRef(el));
+ act(() => hook.result.current.bodyProps.ref(el));
+ expect(hook.result.current.settledOffset).toBe(0);
+
+ act(() => {
+ touch(el, 'touchstart', 300);
+ touch(el, 'touchmove', 250); // pull up
+ });
+ expect(hook.result.current.isDragging).toBe(false);
+ expect(hook.result.current.dragOffset).toBe(0);
+ });
+
+ it('does not preventDefault a bottom pull-up at the tallest detent', () => {
+ // The captured gesture was the worse half of the bug: once promoted,
+ // every later touchmove was preventDefault()ed, so reversing downward to
+ // scroll back collapsed the sheet instead of scrolling.
+ const {hook} = setup({snapHeights: () => [200]});
+ const el = makeScroller({
+ scrollTop: 600,
+ clientHeight: 200,
+ scrollHeight: 800,
+ });
+ act(() => hook.result.current.sheetRef(el));
+ act(() => hook.result.current.bodyProps.ref(el));
+
+ let pullUp: Event | undefined;
+ let reverseDown: Event | undefined;
+ act(() => {
+ touch(el, 'touchstart', 300);
+ pullUp = touch(el, 'touchmove', 250);
+ reverseDown = touch(el, 'touchmove', 400);
+ });
+ expect(pullUp?.defaultPrevented).toBe(false);
+ expect(reverseDown?.defaultPrevented).toBe(false);
+ expect(hook.result.current.isDragging).toBe(false);
});
it('finishes the active drag when another ended touch is listed first', () => {
diff --git a/packages/core/src/BottomSheet/useSheetGestures.ts b/packages/core/src/BottomSheet/useSheetGestures.ts
index 5dc65322f5..e86d7f9ad4 100644
--- a/packages/core/src/BottomSheet/useSheetGestures.ts
+++ b/packages/core/src/BottomSheet/useSheetGestures.ts
@@ -978,7 +978,15 @@ export function useSheetGestures({
return;
}
const top = atTop(scroller);
- const bottom = atBottom(scroller);
+ // The bottom edge hands off so the sheet can EXPAND, so it is only a
+ // handoff when a taller detent exists. Already at the tallest, an
+ // upward pull has nowhere to travel: promoting it would trade the
+ // user's scroll for a rubber-band the release throws straight back, and
+ // — because promotion preventDefault()s the rest of the gesture — would
+ // strand the scroller for as long as the finger stays down, so reversing
+ // downward to scroll back would collapse the sheet instead. Leave the
+ // gesture with the content.
+ const bottom = atBottom(scroller) && activeOffsetRef.current > 0;
if (!top && !bottom) {
touchDragRef.current = null;
return;