Repository navigation
feat(carousel): scroll non-active items into focus on click - #170
Conversation
There was a problem hiding this comment.
📋 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 themd-carousel-item's own shadow root (such as its internala#link) whilst still ignoring clicks on slotted interactive controls like buttons and inputs. - Respecting
prefers-reduced-motionin both the.scrollerstylesheet (scroll-behavior: smoothgated onno-preference) andscrollToIndex, and addingoverscroll-behavior-x: contain, meaningfully improves accessibility and gesture ergonomics. - The new unit tests in
tests/carousel_test.jscover the main interaction paths well, andcarousel/README.mdclearly 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.
…nd Enter handling
There was a problem hiding this comment.
📋 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.mdclearly documents the new click-to-focus behaviour, nested control exclusions, and focal-layout link handling.tests/carousel_test.jsprovides solid coverage for pointer clicks, nested interactive controls, drag/modifier suppression, keyboardEnter/Spaceparity, CSS rules, andprefers-reduced-motion: reducescroll 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.
There was a problem hiding this comment.
📋 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()intorequestAnimationFrame(withcancelAnimationFramecleanup on subsequent scrolls and disconnect) so instant and reduced-motion scrolls preserveis-instant-scrollingandno-transitionuntil the next frame. (carousel/carousel.js:485) - Applied the focal-layout check to unmodified
Enterkey presses on non-activehrefitems in_handleKeyDownso keyboard and pointer navigation behaviours match. (carousel/carousel.js:847) - Cleared
is-instant-scrollingin the'smooth'branch (andis-programmatic-scrollingin the'instant'branch) ofscrollToIndex()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_isNestedInteractiveTargetto 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-layouthreflogic. - Gating
scroll-behavior: smoothbehind@media (prefers-reduced-motion: no-preference)and matching it inscrollToIndex()ensures consistent reduced-motion support across both CSS and programmatic scrolling. - The new
tests/carousel_test.jssuite follows the repository'snode --testconventions 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.
🚀 Deploying Preview to Cloudflare 🚀Preview URL: https://carousel-image-click-navigation-material.treeder.workers.dev (commit b8107d7)This URL reflects your latest Preview deploymentPreview Deployments by commit
|
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
_handleItemClickon.scroller(with_getEventItemand_isNestedInteractiveTarget) to callscrollToIndex(index)when a non-active, enabled item is clicked.button,a[href],input,md-button, etc.), modifier-key clicks, and drag gestures.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; inuncontained, linked cards navigate directly while non-linked cards scroll into focus.Enter/Spaceactivation in_handleKeyDownfor focused non-active items (excluding nested interactive controls and linked items) andcursor: pointerfor non-active, enabled slotted items.overscroll-behavior-x: containon.scrollerand gated smooth scrolling onprefers-reduced-motion: no-preference(falling back to'instant'programmatic scroll under reduced motion).hrefbehavior, 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.