fix: switch bug#989
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🧠 Memory Leak Test ResultsStatus: ✅ All tests passed
📋 Test Details
🤖 Generated by MemLab + Playwright |
🖼️ Visual Regression Test ResultsStatus: ✅ All tests passed
Component Coverage45 / 54 design-toolkit components have VRT tests (83%) Missing VRT tests (9 components)- audio - carousel - deferred-collection - floating-card - gantt - lines - media-controls - status-indicator - video |
📊 Coverage ReportsCoverage Changes by PackageClick to expand 29 package details
Coverage data collected from all packages in the monorepo. |
Screen.Recording.2026-05-05.at.6.39.52.PM.movPR with story that proves out bug here: #991 |
I think I am a little confused about the expectations around this fix. You want the container to scroll out of view with that jump? What is being fixed here? More directly -- on this branch with the style changes, I don't see any difference in the scroll behavior in the reproduction case. I feel like I am missing something. My apologies if I am being really dense...just trying to validate the fix. |
this video is not for this branch; this video is how the switch behaves today demonstrating the bug |
yes! that part makes sense -- but I am trying to say that running the same story on this branch does not appear to fix the bug and I feel like I am missing something. i.e. -- the style.module.css changes don't change behavior for me when I run it. |
|
Hey @sotomaque, could you update your PR description or add in a comment here the code that you wrote up for the repro story shown in the video that demonstrates the issue? Would like to paste it in locally and run it to verify the results. EDIT: Disregard, just saw #991. |
| input. scroll-margin makes scrollIntoView({block:'nearest'}) treat it as | ||
| already visible. */ | ||
| & input { | ||
| scroll-margin: 100vh; |
There was a problem hiding this comment.
This does not fix the problem for switches. I did not check for the other components that this PR updates.
Bug:
<Switch>inside a scrollable container causes the container to auto-scroll, jumping content out from under the user.Root cause:
<input role="switch" type="checkbox">that's visually hidden viaposition: absolute; clip-path: inset(50%); width: 1px; height: 1px;while the visible UI sits in sibling spans.inputRef.current.focus()to move keyboard focus onto the hidden input.focus()is to runscrollIntoView({block: 'nearest'})on the focused element — so it tries to bring a 1×1 pixel element into view, scrolling the nearest scrollable ancestor by however much the input's position differs from the viewport.Fix:
scroll-margin: 100vhto the hidden input inside .switch, .checkbox, and .radio. This convincesscrollIntoView({ block: 'nearest' })that the input is already visible, so the scroll is skipped.