Repository navigation
fix(DateInput): clearing on touch no longer jumps the page to the top - #5350
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR Modified ComponentsDateInput (@astryxdesign/core) · View in Storybook
Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
41d6cb4 to
102fee1
Compare
On the touch surface, tapping the clear (X) threw the user to the top of the
page. Clearing unmounts the clear button, and handleClear focused the field in
that same task; on iOS Safari, focusing an element as the focused button is
removed scrolls the whole document to 0.
The focus handoff is deferred past the unmount. The page stays put and focus
still lands on the field, so it is not lost to <body>.
Measured on the iOS 26 simulator driving real taps against the live docsite
(DateInput - Clearable, page at scrollY 2055), with every scroll API and the
scroll lock instrumented:
synchronous focus() -> 2055 -> 0
synchronous focus({preventScroll}) -> 2055 -> 0
focus suppressed entirely -> 2055 (no move, focus lost)
deferred focus({preventScroll}) -> 2055 (no move, focus kept)
No script scrolls the page: no scrollTo/scroll/scrollBy/scrollIntoView, no
scrollTop write, no history navigation, no scroll-lock body pinning, and the
document height never changes. preventScroll is kept because the ordinary
scroll-into-view nudge is real too (+12px on a plain page) and unwanted for the
same reason.
102fee1 to
12617af
Compare
|
Nice fix — deferring the focus out of the tap is the right call, and the before/after table is the best part of it. The same shape is next door, though: Not asking you to widen this PR. But if the deferral holds up in the field, the durable version of it probably lives in the shared clear handler rather than in each input. [Reviewed by Robohands] |
The bug
On touch, tapping DateInput's clear (✕) throws the user to the top of the page.
Repro (real, on the live docsite): open
https://astryx.atmeta.com/components/DateInput on a phone, scroll to the second
date input — the DateInput — Clearable example, "Event date / April 6,
2026" — and tap its ✕. The page jumps to the top. React state survives, so it
is an in-page scroll jump, not a reload.
Cause
TouchDateField.handleClearclears the value and focuses the field in the sametask. Clearing unmounts the clear button — it only renders while there is a
value — and on iOS Safari, focusing an element in the same task as the focused
button's removal scrolls the whole document to 0.
Measured on the iOS 26 simulator driving real taps against the live docsite,
field at
scrollY 2055, with every scroll API instrumented:focus()(today)focus({preventScroll: true})<body>)focus({preventScroll: true})What is not happening, all instrumented and silent through the jump: no
scrollTo/scroll/scrollBy/scrollIntoView, noscrollTopwrite, nohistory.pushState/replaceState/hashchange, no scroll-lockbodypinning,and
document.scrollHeightnever changes (5156 throughout, so it is not aheight collapse clamping the scroll). Focus on the same field while the page is
quiet does not move it either — the unmount is required.
The fix
Defer the focus handoff past the unmount. The page stays put and focus still
returns to the field, so it is not lost to
<body>.preventScrollis kept: the ordinary scroll-into-view nudge is real too (+12pxon a plain page) and unwanted for the same reason — the field the user just
tapped is already on screen. It is not sufficient on its own, per the table.
Only the touch surface is affected; the pointer surface is a different
component and does not do this.
Test plan
DateInputTouch.test.tsx: focus is not called synchronously,and after timers run it is called with
{preventScroll: true}. Negativecontrol: restoring the synchronous call fails it.
packages/core/src/DateInput— 229 tests pass.pnpm lint:strict— 0 errors (55 pre-existing warnings).pnpm test— 11376 pass; the 11 failures are allpackages/cli, the knowndevvm full-run load flake, green under
vitest run --project node packages/cli(200 files / 2780 tests).pnpm buildplus thebuild-storybooktypechecks(
core|lab|charts typecheck:docs,cli typecheck:{strict,template-docs},storybook typecheck,core typecheck,lab:readiness:check,storybook build) — all exit 0.Note on earlier revisions of this PR
The first version of this PR changed
DateRangeInput,SelectorandMultiSelector— none of which are DateInput and none of which are the touchsurface. That was wrong and has been dropped. Those three do have a separate,
real defect (their clear leaves focus on
<body>); worth its own PR, not thisone.