Skip to content

fix(Carousel): add onKeydown to Next/Previous for non-native element keyboard activation#639

Open
sridhar-3009 wants to merge 2 commits into
vuetifyjs:masterfrom
sridhar-3009:fix/carousel-keyboard-nav-next-prev
Open

fix(Carousel): add onKeydown to Next/Previous for non-native element keyboard activation#639
sridhar-3009 wants to merge 2 commits into
vuetifyjs:masterfrom
sridhar-3009:fix/carousel-keyboard-nav-next-prev

Conversation

@sridhar-3009

Copy link
Copy Markdown
Contributor

Summary

  • Carousel.Next and Carousel.Previous only exposed onClick in their attrs slot props. When rendered with as='div' (or any non-button element), browsers do not synthesize click events from Enter or Space keypresses, silently breaking keyboard navigation for users who rely on keyboards or AT
  • Adds onKeydown handlers to both components that call the existing onClick logic when Enter or Space is pressed — the same pattern already used by CarouselIndicator
  • The onKeydown type is added to CarouselNextSlotProps.attrs and CarouselPreviousSlotProps.attrs so TypeScript consumers know it's available

What changed

  • CarouselNext.vue: new onKeydown function calling onClick() on Enter/Space; exposed in slotProps.attrs; type added to CarouselNextSlotProps
  • CarouselPrevious.vue: same changes symmetrically
  • index.test.ts: two new tests — one for each component — mounting with as='div' and asserting Enter/Space trigger slide navigation

Test plan

  • Carousel.Next rendered as div: Enter key advances to next slide
  • Carousel.Previous rendered as div: Enter key moves to previous slide
  • Space key also triggers navigation (and defaultPrevented)
  • All 100 Carousel tests pass

…keyboard activation

Carousel.Next and Carousel.Previous only exposed onClick in their
slot-prop attrs. When rendered with as='div' (or any non-button
element), browsers do not synthesize click events from Enter/Space
keypresses, silently breaking keyboard navigation.

Add onKeydown handlers to both components that call the existing
onClick logic when Enter or Space is pressed, matching the pattern
already used by CarouselIndicator. Also add tests that mount each
button as as='div' and assert Enter advances/retreats the slide.
@github-actions

github-actions Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Changeset found — this change will be included in the next release. Thanks!

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