Repository navigation
fix(core): hand the Bottom Sheet the pull when its content runs out - #5172
Merged
Merged
Conversation
A swipe that scrolls to the end of the sheet's content and keeps pulling stopped dead at the last line. Arming was decided once, at touchstart: a finger that landed mid-content stayed a scroll for the whole gesture, so the motion people actually perform -- swipe up through the list, reach the bottom, keep pulling -- never reached the sheet. Only a fresh touch that started already at the edge handed off, which is why every scripted repro said the bottom edge was fine. Re-arming on every move and promoting with preventDefault() cannot fix it: once the browser has committed the gesture to scrolling, the remaining touchmoves are non-cancelable (measured in Chrome: 40 moves in the gesture, 12 with the scroller at its end, 0 of them cancelable). Nothing needs cancelling either -- the scroller is clamped at its maximum, so further upward travel scrolls nothing. So the body now tracks every touch, notes where the finger was when the content ran out, and drives the sheet from the travel beyond that point: no jump, and the part of the swipe that legitimately scrolled stays with the content. The handoff yields again if the finger comes back down (the native scroll it handed off from was never cancelled, and two things moving at once is the failure mode), and never fires with no taller detent to expand into, the #5161 rule. Verified in Chrome (~/sheet-repro/continuous-handoff-suite.mjs): the continuous pull expands the sheet 450 -> 342, while mid-content scrolling, the top-edge pull-down, the momentum tail, the reversal, and the tallest-detent case are unchanged.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR Modified ComponentsBottomSheet (@astryxdesign/core) · View in Storybook
Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
imdreamrunner
added a commit
that referenced
this pull request
Aug 18, 2026
Self-review of this PR, with each finding reproduced before it was changed. A regression this PR introduced: behind a NON-MODAL sheet the page stays scrollable by design, and the document-scroll net was reverting the user's own scrolling to wherever the keyboard opened. The net exists for one case — app resume, which raises no focus event to claim — and that case only arises when the page is locked, which is exactly when a document scroll cannot be the user's. The host knows; it now says so through `isPageScrollLocked`, and a test covers a non-modal page scroll. Removed, as machinery for cases that cannot happen: - The re-entrancy guard around the claim. Real WebKit dispatches nothing further once the destination is focused — measured — so the guard was defending a jsdom artifact, and it would have dropped a legitimate chained transition where a consumer's own focus handler moves focus on. Its test went with it. - The global `overscroll-behavior: contain` stylesheet. It addresses scroll chaining, which is a different mechanism, and nothing here was shown to need it. Worth revisiting with a case that fails without it. - A dead `isActiveRef`, orphaned when the tap path went; a `top: 0` that was always zero, so the obstruction is now the single number it always was; and two comments describing a head start that no longer exists. Narrowed: parking focus on the sheet after a blur to nowhere is for keeping the NEXT tap claimable, so it no longer fires while the sheet is closing — the host is restoring focus to the opener there. Every guard now fails a test when removed, including the claim itself. Real story on the simulator, sheet top from the scrim boundary: 376px focused, 376px after six accessory-bar Nexts, 376px across an app switch. Rebased onto main (#5172).
imdreamrunner
added a commit
that referenced
this pull request
Aug 18, 2026
…tom Sheet field (#5158) * fix(core): keep the page still when the mobile keyboard reveals a Bottom Sheet field Only a confirmed single-finger tap was ever protected from iOS's native focus reveal. An accessory-bar Next, a Tab, or a programmatic focus fell through to a scroll snapshot that cannot undo what actually moves: with the sheet in a fixed dialog over a scroll-locked page, the reveal pans the visual viewport, and offsetTop is read-only. Refocusing the destination with preventScroll is what #5043 reverted for duplicating the focus lifecycle (B1), so don't re-enter it. WebKit only pans when the control is still obscured after it scrolls what it can reach, so scroll the destination into the safe area during focusout, before focus lands, and leave the reveal with nothing to do. Two smaller holes alongside it: - At maximum pan the visual viewport's bottom reaches the layout viewport bottom with the keyboard still up, and the hook read that as a dismissal, clearing the inset and the scroll range under the field. Compare heights, which a pan does not change. - A second contact anywhere on the page overwrote the single pending-tap slot, disarming the finger already tapping a field. * chore(changeset): reference the PR * docs(core): say that shorter Bottom Sheet heights leave the native focus reveal in place * fix(core): narrow the second-contact guard to non-primary pointers The guard ignored any pointerdown whose id differed from the armed tap's. That is broader than the bug and it can wedge: if the armed tap's pointerup never reaches the document listener — it is registered in the bubble phase, so a consumer can stop it — the stale arming then blocks every later tap from arming, permanently. Only a primary contact can arm in the first place, so the real defect is narrower: a secondary contact fell through and nulled the arming. Ignore non-primary pointers and nothing else. A fresh primary pointerdown always re-arms, so a stranded arming cannot lock the mechanism out. Also pin the two guards that no test reached: the unobstructed-viewport case now places the destination outside the body's visible area, so it fails if the head start stops being gated on a measured keyboard, and a swallowed pointerup is covered directly. Every guard in the hook now fails a test when removed. * fix(core): put back the document scroll the browser makes to reveal a field Reproduced on an iPhone 17 simulator: focus a field in a Tall sheet, leave Safari, come back, and the whole page is shifted up — and stays there. The instrumented run showed the shift is not the visual-viewport pan this PR assumed. window.scrollY goes to 337 and the sheet, being fixed, travels with it; visualViewport.offsetTop tracks scrollY exactly. It is a real document scroll. useScrollLock pins the body, which stops the USER scrolling but not the browser: revealing a focused control scrolls the document itself. Being a real scroll, it can simply be put back. The document's own scroll event is the earliest signal — a millisecond ahead of visualViewport's — so restore there, synchronously, before the frame is painted, then bring the control into view with the sheet's own scroller. Measured on the simulator: it settles in one step with no oscillation. This corrects the outcome instead of racing the cause, so it covers every route in, including the resume case, where no focus or pointer event fires at all and the head start has nothing to hook into. Restoring window scroll is not new here — restoreFocusScroll already does it; it just runs during the focus event, ~140ms before the browser scrolls. The expected position is captured when the keyboard layout is established, so a non-modal sheet's legitimately scrolled page is restored to where the user left it rather than to zero. Real story on the simulator, same tap sequence, screenshots before and after an app switch: pre-fix 4.3% of pixels differ, with the fix 0.0%. * fix(core): read the keyboard boundary pan-invariantly, everywhere Review caught that the earlier commit fixed one reader of `offsetTop + height` and left three, so a single pan still latched the sheet into the unprotected behavior — matching the device symptom that accessory-bar Next works down a form until something pans once, and from there every Next pans and it never recovers. A fully expanded Tall sheet is pinned to the layout viewport bottom, so bodyBottom == innerHeight. At full pan `offsetTop + height` also equals innerHeight, so overlap computes as 0: the inset is dropped, and hasKeyboardLayout goes false, which disarms the head start. Measured with bodyBottom = innerHeight = 768 and a 500px keyboard: 316px -> 0px, after which this branch behaves exactly like main. The pan-invariant quantity is the one the recovery check already uses. The keyboard covers the bottom of the LAYOUT viewport, so its top edge sits at visualViewport.height in client coordinates and stays there under a pan — a pan slides the window over the page without moving the keyboard. getUnobstructedBounds() returns that band and every reader takes it. Identical when offsetTop is 0, so nothing off the pan path moves. The previous test for this passed only because rect({bottom: 800}) against jsdom's innerHeight of 768 left a 32px cushion, and its 348px -> 80px expectation encoded the bug: 268px of scroll range vanishing during a pure pan. Both keyboard geometry tests now pin the body to innerHeight, the way the real sheet sits. Also from the same review: - The tap path was taking the head start it does not need — it already focused with preventScroll — turning a glide between two fields into a snap. pendingPointerFocusScroll identifies it. - The multi-touch guard covered pointerdown but not pointerup, so a resting thumb that lifted first still disarmed the tap in progress. - scrollBy 'auto' defers to the element's computed scroll-behavior; 'instant' is what a scroll racing the browser means. Real story on the simulator, sheet top edge decoded from the scrim boundary: 376px at rest, 376px after four accessory-bar Nexts, 376px after eight, 376px across an app switch. Rebased onto main, which lands the same insight in useSheetGestures (#5159). * fix(core): drop the isPrimary check the early return subsumes tsc caught it: the new guard narrows event.isPrimary to true, so the later 'isPrimary !== false' compares two disjoint literal types. Only the build runs tsc over this file — lint:strict and vitest both pass it. * fix(core): claim the focus transition instead of chasing the scroll The browser reveals a newly focused field by scrolling the document, and a fixed sheet rides along. Everything here so far tried to get in front of that scroll or undo it afterwards, and both are races: the reveal runs on the compositor, so the correction can land a frame late and read as a pan followed by a snap back. The reveal is attached to the focus operation, which is where it can be refused. `blur` is dispatched in the capture phase ahead of the browser's own focus step and names the destination in `relatedTarget`: focus it there with preventScroll and the transition is settled before the browser starts one. Its focus step finds the element already active, dispatches nothing, and has nothing to reveal. A tap, the keyboard's Next, Tab and a programmatic focus() all pass through that single transition, so the special-cased tap path is gone with it. Measured on an iPhone 17 simulator, counting real focus events with the takeover on and off — tap-to-tap, accessory Previous/Next, and programmatic a.focus()/b.focus() — every case is exactly one focus, one focusin, one blur, one focusout per transition, identical either way. That is PR #5043's B1 concern, which blocked this approach: it does not reproduce in WebKit. It does reproduce in jsdom, whose focus() is not re-entrancy-safe, so the handler ignores a blur raised by its own delivery and a test pins that. Also from the same pass: - Revealing the field is left to the existing focusin/viewport-resize path rather than duplicated in the new handler. - A blur to nowhere — the keyboard's Done button — parks focus on the sheet. Left on the body, the field is still activeElement on the next tap, so no transition fires and the browser reveals it its own way. - `overscroll-behavior: contain` ships as a stylesheet in its own layer while the sheet is open. Current iOS latches this at touchstart, too late for a listener to set, and the sheet body's own rule does not cover a nested scroller in consumer content. The document-scroll restoration stays: app resume raises no focus event at all, so it is the only thing covering that case, and a test fails without it. Real story on the simulator, sheet top decoded from the scrim boundary: 376px focused, 376px after six accessory-bar Nexts, 376px across an app switch. Net -53 lines in the hook. * fix(core): scope the keyboard hook to what it can prove Self-review of this PR, with each finding reproduced before it was changed. A regression this PR introduced: behind a NON-MODAL sheet the page stays scrollable by design, and the document-scroll net was reverting the user's own scrolling to wherever the keyboard opened. The net exists for one case — app resume, which raises no focus event to claim — and that case only arises when the page is locked, which is exactly when a document scroll cannot be the user's. The host knows; it now says so through `isPageScrollLocked`, and a test covers a non-modal page scroll. Removed, as machinery for cases that cannot happen: - The re-entrancy guard around the claim. Real WebKit dispatches nothing further once the destination is focused — measured — so the guard was defending a jsdom artifact, and it would have dropped a legitimate chained transition where a consumer's own focus handler moves focus on. Its test went with it. - The global `overscroll-behavior: contain` stylesheet. It addresses scroll chaining, which is a different mechanism, and nothing here was shown to need it. Worth revisiting with a case that fails without it. - A dead `isActiveRef`, orphaned when the tap path went; a `top: 0` that was always zero, so the obstruction is now the single number it always was; and two comments describing a head start that no longer exists. Narrowed: parking focus on the sheet after a blur to nowhere is for keeping the NEXT tap claimable, so it no longer fires while the sheet is closing — the host is restoring focus to the opener there. Every guard now fails a test when removed, including the claim itself. Real story on the simulator, sheet top from the scrim boundary: 376px focused, 376px after six accessory-bar Nexts, 376px across an app switch. Rebased onto main (#5172). * fix(core): refuse the reveal when the sheet autofocuses a field Review found the claim has a blind spot: presenting a sheet that autofocuses a field is not a transition. Nothing was focused, so no blur names the destination, and `focusPanel` was delivering that focus unprevented — leaving the browser to reveal the field by scrolling the page, the exact bug this PR is about. Both of its focus calls now pass preventScroll; the sheet was about to show the field anyway, and useMobileKeyboard brings it into view within the sheet. Also from the same review: - Two tests asserted nothing. They fired pointerdown/pointerup and expected no focus, but the hook has had no pointer listeners since the claim replaced them, so both passed at every height and detent — the opposite of what they are named for. They now drive a blur-named transition, which is what the gate actually governs, and the shorter- detent one fails when that gate is removed. The last user of `fireTouchPointer` went with them, so the helper is gone. - The `height` doc said which heights opt out but not that a Tall sheet opts out under the user's own drag and opts back in when dragged up. It says so now. Caret placement was raised as an untested assumption, since claiming the focus ahead of the click could cost the tap's caret position. Measured in Mobile Safari, tapping into the middle of a populated field with a prior field focused: caret offset 40 of 40 with the claim, and 40 of 40 without it. Identical, so the click's hit test still owns the caret. A tap into a field that is already focused cannot be affected at all — the claim no-ops when the destination is already active.
imdreamrunner
added a commit
that referenced
this pull request
Aug 18, 2026
… iOS (#5178) Below the tallest detent, a pull up inside the sheet's content did nothing on a real device while the grab handle worked fine. iOS Safari raises PointerEvents for a finger under the SAME numeric id it puts in `Touch.identifier`. The touch path builds its pointer-shaped event out of that identifier, so the drag it starts is keyed to a live pointer: `beginDrag` captures it, WebKit takes the capture straight back for its own gesture handling, and the `lostpointercapture` that follows a millisecond later cancels the drag one event after it began. Measured on iOS 26.5, one gesture: touchmove #1 -> promote, beginDrag gotpointercapture pointerId=-1239851261 (= the Touch.identifier) lostpointercapture pointerId=-1239851261 willCancel=true cancelDrag touchmove #2..#50 drag gone; the sheet ignores the rest of the pull Chromium keeps the two id spaces apart, so emulated touch never reproduces it; the unit tests stub `setPointerCapture`, so jsdom never fires the cancelling event. The handle keeps working because it runs on real pointer events, which legitimately hold the capture. The mid-gesture content-end handoff (#5172) usually survives only by timing: it promotes after WebKit has already given up that pointer at scroll commit. Touch-driven drags are now marked as such. They take no pointer capture, and `lostpointercapture`, `pointercancel` and `pointermove` for the same finger no longer cancel, end, or double-drive them. Test Plan: - Two new cases in useSheetGestures.test.ts dispatch onLostPointerCapture and onPointerCancel with a pointerId equal to the touch identifier. Both fail on main ("expected false to be true") and pass here. - packages/core/src/BottomSheet suite: 163/163. - On an iPhone 17 Simulator (iOS 26.5), one continuous touch per case, sheet at the 0.5 detent; numbers are the scrolling body's height, 309 = mid detent, 395 = fully open: | case | before | after | |------------------------------------------|-------------|-----------| | fresh touch at the content end, pull up | 309 (inert) | 309 -> 395| | scroll to the end mid-gesture, keep pull | 309 -> 395 | unchanged | | top-edge pull-down in the body | 395 -> 309 | unchanged | | ordinary mid-content scroll | scroll only | unchanged | | grab-handle drag | works | works | - tsc --noEmit clean; lint:strict 0 errors.
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix(core): hand the Bottom Sheet the pull when its content runs out
The bug
With the sheet below its tallest detent and its content scrollable, a swipe
that scrolls to the end of the content and keeps pulling stopped dead at the
last line. The sheet never expanded, and on iOS the scroller rubber-banded and
sprang back — "the dragging doesn't follow my finger, it resets after a couple
of ms".
Arming was decided once, at
touchstart, and never revisited: a finger thatlanded mid-content stored
null, andonTouchMovereturned immediately for therest of the gesture. So the motion people actually perform — swipe up through
the list, reach the bottom, keep pulling in one continuous gesture — never
handed off. Only a fresh touch that began already at the edge did, which is why
this looked fine in every scripted repro: they set
scrollTopprogrammaticallyand then started a new touch at the edge.
Why the obvious fix doesn't work
Re-evaluating the edge on every move and promoting with
preventDefault()cannot work. Once the browser has committed a gesture to scrolling, the
remaining
touchmoves are not cancelable. Measured in Chrome over onecontinuous swipe: 40 moves in the gesture, 12 with the scroller at its end,
0 of those cancelable. That is also why the old design worked for the
discrete case — it promotes on the first move, the one move still cancelable.
Nothing needs cancelling at that edge anyway: the scroller is clamped at its
maximum, so further upward travel scrolls nothing.
The fix
The body's touch listeners now track every touch, not only the ones that begin
at an edge, and hand off without cancelling anything:
ran out is recorded, and the sheet is driven from the travel beyond it. The
part of the swipe that legitimately scrolled stays with the content, so there
is no jump.
rest on the last pixel doesn't start a drag on jitter.
preventDefault()on this path, including after promotion. Claimingthe gesture is exactly what stranded the scroller in fix(core): a bottom-edge pull-up no longer hijacks a fully expanded Bottom Sheet #5161.
comes back down to the anchor the sheet drag is cancelled and the content
scrolls again; pulling past the end later promotes again. Otherwise the sheet
and the content would move at once.
taller detent exists (fix(core): a bottom-edge pull-up no longer hijacks a fully expanded Bottom Sheet #5161), so a fully expanded sheet still leaves the pull
to the content.
The symmetric top-edge case — scroll up to the top mid-gesture and keep pulling
down — is deliberately left alone. The mechanism would transfer, but the
consequences do not: a mis-fire at the bottom expands a sheet, a mis-fire at the
top collapses or dismisses one. That is a separate decision.
Verification
~/sheet-repro/continuous-handoff-suite.mjs— one real touch sequence per case,no programmatic
scrollTop, capped-height story at 500×900. Run against theunfixed build and this one:
Only the reported case changes.
Unit tests: three new cases in
useSheetGestures.test.tsfail on the unfixedsource and pass here; they assert travel and
defaultPrevented, not justisDragging. BottomSheet suite: 155 green.pnpm check:repo, eslint, andtsc --noEmitclean.Device confirmation on the reporter's iPhone is still outstanding — in
particular whether WebKit bounces the scroller past its end despite the body's
overscroll-behavior: none.