Skip to content

fix(Carousel): make slide indicators keyboard accessible#978

Open
ifeichuan wants to merge 1 commit into
DavidHDev:mainfrom
ifeichuan:feat/carousel-keyboard-accessible-indicators
Open

fix(Carousel): make slide indicators keyboard accessible#978
ifeichuan wants to merge 1 commit into
DavidHDev:mainfrom
ifeichuan:feat/carousel-keyboard-accessible-indicators

Conversation

@ifeichuan

Copy link
Copy Markdown

Summary

Fixes #976. The Carousel slide indicators were rendered as <motion.div> elements with only an onClick handler, 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 active
  • button resets (border/padding/appearance in CSS variants, border-0 p-0 appearance-none in Tailwind variants) — keep the dot styling identical
  • a :focus-visible outline — 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:

Check Result
Indicators are <button> with type="button", aria-label, aria-current
Tab focuses each indicator in order (slide 1 → 2 → 3 → 4)
Enter on a focused indicator changes the slide
Space on a focused indicator changes the slide
:focus-visible shows a 2px outline on keyboard focus, none on mouse click

The focus-visible outline style follows the existing convention in the repo (e.g. LogoLoop, GlassSurface).

Note: registry artifacts under public/r/ are not included, matching how prior component PRs (e.g. #977) leave registry regeneration to the maintainer build.

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).
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.

[BUG]: Carousel indicators are not keyboard accessible

1 participant