fix(carousel): add vertical keyboard nav and aria-live announcements#10226
Open
mahmoodhamdi wants to merge 1 commit intoshadcn-ui:mainfrom
Open
fix(carousel): add vertical keyboard nav and aria-live announcements#10226mahmoodhamdi wants to merge 1 commit intoshadcn-ui:mainfrom
mahmoodhamdi wants to merge 1 commit intoshadcn-ui:mainfrom
Conversation
…lity - Fix shadcn-ui#10219: handleKeyDown now uses ArrowUp/ArrowDown for vertical orientation and ArrowLeft/ArrowRight for horizontal; adds orientation to dep array - Fix shadcn-ui#10220: accept aria-label prop on Carousel and forward it to the region div; add visually-hidden aria-live="polite" region that announces current slide index ("Slide X of Y") on every navigation event - Fix missing api?.off("reInit", onSelect) in useEffect cleanup - Applied to all three variants: bases/base, bases/radix, new-york-v4
Contributor
|
@mahmoodhamdi is attempting to deploy a commit to the shadcn-pro Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Two accessibility improvements for the Carousel component:
orientation="vertical"aria-liveregion that announces current slide positionWhy
Keyboard navigation (#10219)
The
handleKeyDownhandler only listened forArrowLeft/ArrowRight, making vertical carousels inaccessible via keyboard. Per WAI-ARIA Carousel Pattern, directional keys should match the carousel orientation.Screen reader support (#10220)
The carousel
role="region"had no mechanism to announce slide changes. Screen reader users had no way to know which slide they were on or how many slides existed.How
Keyboard fix
Replaced hardcoded arrow key strings with orientation-aware variables:
Added
orientationto theuseCallbackdependency array.Aria-live region
currentSlideandslideCountstate, updated inonSelect<span aria-live="polite" aria-atomic="true">that announces "Slide X of Y"aria-labelprop forwarded to therole="region"containerapi?.off("reInit", onSelect)in useEffect cleanupFiles changed (3)
All three carousel variants updated consistently:
apps/v4/registry/bases/base/ui/carousel.tsxapps/v4/registry/bases/radix/ui/carousel.tsxapps/v4/registry/new-york-v4/ui/carousel.tsxTesting
aria-labelis optional, keyboard behavior is backward-compatibleCloses #10219
Closes #10220