fix(Carousel): make slide indicators keyboard accessible#978
Open
ifeichuan wants to merge 1 commit into
Open
Conversation
The slide indicators were rendered as `<motion.div>` with only an `onClick` handler, so keyboard-only users could neither focus them with Tab nor activate them with Enter/Space (issue DavidHDev#976). Switch the indicators to `<motion.button type="button">`, which is natively focusable and activatable via Enter/Space, and add: - `aria-label="Go to slide N"` so screen readers announce each control - `aria-current` to expose which slide is active - button resets (border/padding/appearance) to preserve the dot styling - a `:focus-visible` outline so keyboard focus is visible Updated across all 4 variants (JS/TS x CSS/Tailwind).
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.
Summary
Fixes #976. The Carousel slide indicators were rendered as
<motion.div>elements with only anonClickhandler, so keyboard-only users could neither focus them with Tab nor activate them with Enter/Space.This switches the indicators to native
<motion.button type="button">, which is focusable and Enter/Space-activatable for free, and adds the supporting a11y semantics:aria-label="Go to slide N"— screen readers now announce each control (previously empty<div>)aria-current— exposes which slide is activeborder/padding/appearancein CSS variants,border-0 p-0 appearance-nonein Tailwind variants) — keep the dot styling identical:focus-visibleoutline — keyboard focus is now visible (no outline on mouse click)Mouse, drag and touch behaviour are unchanged.
Updated across all 4 variants (JS/TS × CSS/Tailwind), per the contributing guidelines.
How it was tested
Ran the demo locally (
/components/carousel) and verified in a real browser:<button>withtype="button",aria-label,aria-current:focus-visibleshows a 2px outline on keyboard focus, none on mouse clickThe focus-visible outline style follows the existing convention in the repo (e.g.
LogoLoop,GlassSurface).