Skip to content

feat(carousel): scroll non-active items into focus on click - #170

Merged
treeder merged 3 commits into
mainfrom
carousel_image_click_navigation
Nov 26, 2026
Merged

treeder merged 3 commits into
mainfrom
carousel_image_click_navigation

Conversation

@treeder

@treeder treeder commented Nov 26, 2026

Copy link
Copy Markdown
Member

Summary

Adds click-to-focus navigation to <md-carousel> so clicking a non-active item smoothly scrolls it into the focal/main position instead of doing nothing.

Key Changes

  • Click-to-focus (carousel/carousel.js):
    • Added _handleItemClick on .scroller (with _getEventItem and _isNestedInteractiveTarget) to call scrollToIndex(index) when a non-active, enabled item is clicked.
    • Preserves clicks on already-active items, nested interactive controls (button, a[href], input, md-button, etc.), modifier-key clicks, and drag gestures.
    • In focal layouts (multi-browse, hero, centered-hero), clicking a non-active linked (href) item focuses it first (preventDefault()) and allows normal navigation on a subsequent click once active; in uncontained, linked cards navigate directly while non-linked cards scroll into focus.
    • Added Enter/Space activation in _handleKeyDown for focused non-active items (excluding nested interactive controls and linked items) and cursor: pointer for non-active, enabled slotted items.
    • Added overscroll-behavior-x: contain on .scroller and gated smooth scrolling on prefers-reduced-motion: no-preference (falling back to 'instant' programmatic scroll under reduced motion).
  • Docs (carousel/README.md): Documented click-to-focus behavior.
  • Tests ( ests/carousel_test.js): Added 9 unit tests covering multi-browse click focus, active item passthrough, focal vs. uncontained href behavior, nested controls, drag/modifier/disabled guards, keyboard activation, and reduced-motion scrolling.

Verification

  • npm test (node --test tests/*_test.js): 35/35 tests passing across 6 suites.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📋 Review Summary

This pull request adds click-to-focus and keyboard activation for non-active carousel items in md-carousel, along with overscroll-behavior-x: contain, prefers-reduced-motion scroll handling, updated documentation in carousel/README.md, and unit tests in tests/carousel_test.js. The implementation carefully preserves nested interactive controls, drag gestures, and modifier-key link clicks while staging focus before navigation for linked items in focal layouts. Overall the change is clean and well-tested, with two medium-severity issues around instant/reduced-motion transition suppression and keyboard consistency for linked items in focal layouts.

🔍 General Feedback

  • Good shadow-boundary handling in _isNestedInteractiveTarget, which skips nodes inside the md-carousel-item's own shadow root (such as its internal a#link) whilst still ignoring clicks on slotted interactive controls like buttons and inputs.
  • Respecting prefers-reduced-motion in both the .scroller stylesheet (scroll-behavior: smooth gated on no-preference) and scrollToIndex, and adding overscroll-behavior-x: contain, meaningfully improves accessibility and gesture ergonomics.
  • The new unit tests in tests/carousel_test.js cover the main interaction paths well, and carousel/README.md clearly documents the new click-to-focus behaviour.
📊 Token Usage & Cost Efficiency
Metric Value
Input Tokens (uncached) 3,384
Input Tokens (cached) 97,788 (⚡ 96.7% cached)
Thinking / Reasoning Tokens 17,628
Output Tokens 714
Dynamic Context Selection Tokens 3,612
Total Session Tokens 123,126
Cost (uncached input) $0.0051
Cost (cached input) $0.0073
Cost (thinking / reasoning) $0.1322
Cost (response output) $0.0054
Cost (context selection) $0.0084
Estimated Total Cost $0.1584

Gemini 4 Hydrogen: standard tier, global endpoint; regional endpoints are 10% higher.
Cache reads are priced here, but context-cache STORAGE, where the model charges for it separately per token-hour, is not included, so the figure can run slightly low.

Comment thread carousel/carousel.js Resolved
Comment thread carousel/carousel.js Resolved

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📋 Review Summary

This PR adds click-to-focus and keyboard activation for non-active items in <md-carousel>, improves prefers-reduced-motion and overscroll containment handling, updates carousel/README.md, and introduces unit tests in tests/carousel_test.js. Both prior review items regarding requestAnimationFrame cleanup for instant scrolls and focal-layout Enter parity for linked items have been cleanly addressed. One medium-severity issue remains in scrollToIndex(): when a 'smooth' scroll cancels a pending 'instant' scroll's requestAnimationFrame, is-instant-scrolling is not cleared from .scroller.

✅ Resolved Items from Prior Reviews

  • Deferred endProgrammaticScroll() into requestAnimationFrame (with cancelAnimationFrame cleanup on subsequent scrolls and disconnect) so instant and reduced-motion scrolls preserve is-instant-scrolling and no-transition until the next animation frame. (carousel/carousel.js:483)
  • Applied the focal-layout check to unmodified Enter key presses on non-active linked (href) items so keyboard navigation matches pointer click behaviour. (carousel/carousel.js:845)

🔍 General Feedback

  • _isNestedInteractiveTarget() cleanly distinguishes slotted interactive controls from <md-carousel-item>'s own shadow DOM link wrapper, preventing click hijacking on nested buttons, inputs, or links while still allowing click-to-focus on media items.
  • carousel/README.md clearly documents the new click-to-focus behaviour, nested control exclusions, and focal-layout link handling.
  • tests/carousel_test.js provides solid coverage for pointer clicks, nested interactive controls, drag/modifier suppression, keyboard Enter/Space parity, CSS rules, and prefers-reduced-motion: reduce scroll cleanup.
📊 Token Usage & Cost Efficiency
Metric Value
Input Tokens (uncached) 2,854
Input Tokens (cached) 94,170 (⚡ 96.6% cached)
PR Comments History Tokens 493
Thinking / Reasoning Tokens 10,857
Output Tokens 582
Dynamic Context Selection Tokens 3,662
Total Session Tokens 112,618
Cost (uncached input) $0.0050
Cost (cached input) $0.0071
Cost (thinking / reasoning) $0.0814
Cost (response output) $0.0044
Cost (context selection) $0.0088
Estimated Total Cost $0.1067

Gemini 4 Hydrogen: standard tier, global endpoint; regional endpoints are 10% higher.
Cache reads are priced here, but context-cache STORAGE, where the model charges for it separately per token-hour, is not included, so the figure can run slightly low.

Comment thread carousel/carousel.js Resolved

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📋 Review Summary

This pull request adds click-to-focus and keyboard activation (Enter/Space) for non-active items in <md-carousel>, updates carousel/README.md to document the behaviour, refines reduced-motion and instant-scroll handling with overscroll-behavior-x: contain, and introduces a unit test suite in tests/carousel_test.js. Previously raised issues regarding deferred requestAnimationFrame cleanup for instant/reduced-motion scrolls, consistent focal-layout handling of href items on Enter, and clearing stale is-instant-scrolling classes when interrupted by a smooth scroll have all been cleanly addressed and covered by tests.

✅ Resolved Items from Prior Reviews

  • Deferred endProgrammaticScroll() into requestAnimationFrame (with cancelAnimationFrame cleanup on subsequent scrolls and disconnect) so instant and reduced-motion scrolls preserve is-instant-scrolling and no-transition until the next frame. (carousel/carousel.js:485)
  • Applied the focal-layout check to unmodified Enter key presses on non-active href items in _handleKeyDown so keyboard and pointer navigation behaviours match. (carousel/carousel.js:847)
  • Cleared is-instant-scrolling in the 'smooth' branch (and is-programmatic-scrolling in the 'instant' branch) of scrollToIndex() so interrupting a pending instant-scroll animation frame does not leave stale scroll classes on .scroller. (carousel/carousel.js:377)

🔍 General Feedback

  • Good use of composedPath() in _isNestedInteractiveTarget to avoid hijacking clicks on slotted interactive controls while still allowing <md-carousel-item>'s own internal shadow DOM <a class="link"> to be managed by the focal-layout href logic.
  • Gating scroll-behavior: smooth behind @media (prefers-reduced-motion: no-preference) and matching it in scrollToIndex() ensures consistent reduced-motion support across both CSS and programmatic scrolling.
  • The new tests/carousel_test.js suite follows the repository's node --test conventions and provides solid coverage for click-to-focus, nested controls, modifier keys, drag suppression, keyboard activation, reduced motion, and interrupted instant scrolls.
📊 Token Usage & Cost Efficiency
Metric Value
Input Tokens (uncached) 2,612
Input Tokens (cached) 95,209 (⚡ 96.6% cached)
PR Comments History Tokens 748
Thinking / Reasoning Tokens 10,087
Output Tokens 594
Dynamic Context Selection Tokens 3,641
Total Session Tokens 112,891
Cost (uncached input) $0.0050
Cost (cached input) $0.0071
Cost (thinking / reasoning) $0.0757
Cost (response output) $0.0045
Cost (context selection) $0.0087
Estimated Total Cost $0.1010

Gemini 4 Hydrogen: standard tier, global endpoint; regional endpoints are 10% higher.
Cache reads are priced here, but context-cache STORAGE, where the model charges for it separately per token-hour, is not included, so the figure can run slightly low.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview URL: https://carousel-image-click-navigation-material.treeder.workers.dev (commit b8107d7)

This URL reflects your latest Preview deployment

Preview Deployments by commit

Status Deployment URL Commit Updated (UTC) See this deployment's details
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://735f241c-material.treeder.workers.dev b8107d7 2026-11-26T02:32:36.356Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://a6cb3960-material.treeder.workers.dev ef5c9b5 2026-11-26T02:35:04.439Z Visit the dashboard ↗

@treeder
treeder merged commit d455266 into main Nov 26, 2026
2 checks passed
@treeder
treeder deleted the carousel_image_click_navigation branch November 26, 2026 02:43
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.

1 participant