Skip to content

ui-carousel: Fix unnecessary scroll of carousel items into view - #155

Merged
microbit-matt-hillsdon merged 3 commits into
mainfrom
carousel-scroll-fix
Sep 15, 2026
Merged

microbit-matt-hillsdon merged 3 commits into
mainfrom
carousel-scroll-fix

Conversation

@microbit-robert

Copy link
Copy Markdown
Contributor

Adds a story for a carousel of project cards with actions used to reproduce the bug and test the fix.

Closes #154

Comment thread packages/ui-carousel/package.json Outdated
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Sep 14, 2026

Copy link
Copy Markdown

Deploying ui with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5882e73
Status: ✅  Deploy successful!
Preview URL: https://82e641cc.ui-2wg.pages.dev
Branch Preview URL: https://carousel-scroll-fix.ui-2wg.pages.dev

View logs

@microbit-matt-hillsdon

Copy link
Copy Markdown
Contributor

So we still move a full card width for the sake of a pixel off screen which can feel a bit weird when your click target was fully visible. Say in a two-cards-minus-one-pixel width setup, RH edge just off screen click clearly visible and 100% on-screen button. Maybe the click target should stop propagation (untested) ? Let's chat briefly about this tomorrow.

@microbit-matt-hillsdon

Copy link
Copy Markdown
Contributor

So we still move a full card width for the sake of a pixel off screen which can feel a bit weird when your click target was fully visible. Say in a two-cards-minus-one-pixel width setup, RH edge just off screen click clearly visible and 100% on-screen button. Maybe the click target should stop propagation (untested) ? Let's chat briefly about this tomorrow.

Or as Claude suggests:

The right distinction is pointer versus keyboard, not visible versus not. If the user clicked or tapped something, it was on screen. Focus-follows-slide only needs to run when focus arrived by keyboard or a screen reader. react-aria tracks this globally and the repo already uses it, for example useFocusVisible in ComboBox. The carousel handler could early-return when getInteractionModality() is "pointer", or equivalently when isFocusVisible() is false. React-aria's press handling focuses the button on pointerdown, after the modality has been set to pointer, so the ordering works. The visibility check would stay as a secondary guard for keyboard focus.

Pressing a visible card control (e.g. the project menu button) focuses
it, which moved the carousel if the card overlapped Swiper's content
box by even a pixel. Only keyboard focus now slides a card into view.
@microbit-matt-hillsdon

Copy link
Copy Markdown
Contributor

Added the modality fix. Couldn't use react-aria's notion as it's React state which can be updated too late for the carousel but easy enough to track by hand.

@microbit-matt-hillsdon
microbit-matt-hillsdon merged commit 83aa595 into main Sep 15, 2026
4 checks passed
@microbit-matt-hillsdon
microbit-matt-hillsdon deleted the carousel-scroll-fix branch September 15, 2026 11:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ui-carousel: Unwanted carousel scrolling when clicking on project card actions button

2 participants