Skip to content

Make toggle switches keyboard-accessible #50

Description

@coderabbitai

Context

In PR #49, the toggle switches in the stimulus-components-app example use <div> elements with click handlers, which blocks keyboard interaction for users who navigate without a mouse.

Requested by: @stofu1234
Original discussion: #49 (comment)

Goal

Convert the toggle switches to use semantic <button> elements with:

  • role="switch"
  • aria-checked attribute that updates when toggled
  • Keyboard support (Enter/Space keys)

This enhancement will make the toggle components accessible to keyboard-only users and screen reader users.

Scope

Affects three toggle instances in examples/stimulus-components-app/index.html:

  1. Notifications toggle
  2. Dark Mode toggle
  3. Show Details toggle

The toggle controller (toggle_controller.rb) should be updated to maintain aria-checked state in sync with the visual state.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions