Skip to content

ol-carousel touch gestures and swipe physic refinements#13101

Open
lokesh wants to merge 2 commits into
internetarchive:masterfrom
lokesh:ol-carousel-refinements
Open

ol-carousel touch gestures and swipe physic refinements#13101
lokesh wants to merge 2 commits into
internetarchive:masterfrom
lokesh:ol-carousel-refinements

Conversation

@lokesh

@lokesh lokesh commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Follow-up polish to #13077 (no linked issue).

A set of refinements to <ol-carousel>: smoother touch swiping, smarter cover-image loading, and full keyboard navigation.

carousel.mp4

Touch & swipe

  • Starting a vertical page scroll on the carousel no longer triggers an accidental page-flip
  • Swiping horizontally no longer scrolls the page up and down at the same time
  • Angled swipes (up to ~63° from horizontal) now catch into the carousel instead of losing out to page scroll
  • Long drags can cross multiple pages and settle on the nearest one, instead of snapping back
  • Release momentum is smoother and more predictable — no more surprise flings after pausing mid-drag

Cover loading

  • Off-screen book covers start loading as soon as you hover over or tab into a carousel, so the next page's covers are ready before you reach them
  • Skipped on data-saver / slow connections, so it never wastes mobile data

Keyboard

  • The page indicators are now arrow-key navigable (←/→, Home, End), following the standard tabs pattern

Testing

  1. Open /developers/design#carousel (use Chrome device mode for touch)
  2. Swipe the carousel left/right — the page shouldn't scroll vertically during the swipe, and moderate-angle swipes should still move the carousel
  3. Swipe repeatedly, including after page transitions — every swipe should work
  4. Hover over or tab into a carousel of books — the next page's covers should load ahead of time
  5. With indicators shown, use ←/→/Home/End to move between pages

No visual changes. Tests live in tests/unit/js/OlCarousel.test.js (18 tests) covering the gesture behavior and keyboard navigation.

Stakeholders

@RayBB

Touch swipes were unreliable: starting a vertical page scroll on the
carousel could fire a page navigation (pointercancel was handled as a
release), horizontal swipes scrolled the page underneath, and after the
first page transition the swipe surface went dead on iOS (the
pointerdown listener lived on the translated track).

- Resolve gesture ownership with an axis lock (8px dead zone, 2:1
  horizontal bias) and preventDefault page scroll once locked
- Treat pointercancel as an abort that springs home, never a navigation
- Move gesture listeners to the untransformed viewport so the whole
  surface stays swipeable on every page
- Smooth velocity (EMA over >=4ms windows, capped, stale samples
  discarded) so release momentum is stable
- Land long drags on the nearest page; momentum carries at most one
  page beyond it

Adds a jest suite covering the gesture state machine.
@lokesh lokesh marked this pull request as ready for review July 6, 2026 19:43
@lokesh lokesh changed the title Fix ol-carousel touch gestures and refine swipe physics ol-carousel touch gestures and swipe physic refinements Jul 10, 2026
ol-carousel refinements:
- Deepen the cover lookahead from one page to two on the first hover or
  keyboard focus, so fast page-flipping stays ahead of the loaded range.
  Skipped on data-saver / 2g connections; fires at most once.
- Add arrow-key / Home / End navigation to the page-indicator tablist
  with a roving tabindex (APG Tabs pattern), plus tests.
- Regenerate custom-elements.json to match.
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.

2 participants