Skip to content

fix(switch): hide a read-only switch in a switch row with aria-hidden - #5254

Open
lukewalczak wants to merge 1 commit into
mainfrom
fix/switch-aria-hidden
Open

lukewalczak wants to merge 1 commit into
mainfrom
fix/switch-aria-hidden

Conversation

@lukewalczak

Copy link
Copy Markdown
Member

Motivation

The migration guide's pattern for a switch row nests <Switch readOnly /> in an aria-hidden view inside a row with role="switch". A read-only Switch still renders its own role="switch" and a tabIndex, because React Native Web's Pressable always sets one. So on web axe reports nested-interactive (serious), and on Android the row contains a second, disabled android.widget.Switch.

Switch now accepts aria-hidden. A readOnly or disabled switch given aria-hidden renders a plain view with no role and no tabIndex. The prop has no effect on an interactive switch. The guide sample and the example app put aria-hidden on the Switch itself:

 <View pointerEvents="none">
-  <Switch value={isDarkTheme} />
+  <Switch value={isDarkTheme} readOnly aria-hidden />
 </View>

Related issue

Fixes #5245

Screenshots / Videos

None: rendering doesn't change. Accessibility tree, example app, TextInput › Controls:

main this branch
Web, axe nested-interactive (TextInput) 18 violations 0
Web, axe nested-interactive (FAB, "Show FAB") 1 violation 0
Android, android.widget.Switch nodes 18 (one nested per row) 9 (one per row)
iOS, Switch elements one per row one per row (unchanged)

Test plan

  • Web (npx expo start --web in example/):
    • Run axe on TextInput › Controls, Floating Action Button › "Show FAB", and the drawer: no nested-interactive violations.
    • Tab through the Controls rows: focus moves row to row and skips the inner switch. Enter or a click toggles the row, and the inner switch shows the new state.
    • On the Switch screen, the standalone read-only switch still has role="switch", tabIndex=-1 and aria-readonly.
  • Android (Pixel 8 Pro emulator): on TextInput › Controls, each row is a single switch node with no nested switch. Tapping a row toggles it.
  • iOS (iPhone 17 Pro simulator): on TextInput › Controls, each row is a single switch element, and tapping a row toggles its value.
  • TalkBack and VoiceOver were not run.

@github-actions

Copy link
Copy Markdown

Found potential problems with the pull request:

  • The description is too long. Please keep it under 1000 characters.
  • Screenshot or video evidence is missing. Make sure to include one if it affects the UI.

@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve · review of bb0e6e3

No open findings.

1 finding below minor hidden (user_settings.min_severity).

Reviewed with this repository's own Sentinel configuration (3d9dee332cd6).

💬 Talking to Sentinel

In a finding's thread, reply with:

Command What it does
@apex-sentinel-staging note <context> Adds context; Sentinel re-checks the cited code
@apex-sentinel-staging pivot <why> Says the finding is wrong; Sentinel re-checks the cited code
@apex-sentinel-staging like Marks the finding as useful
@apex-sentinel-staging dislike <why> Marks it as not useful, so it is not raised again

On this conversation, comment @apex-sentinel-staging review to run a full review once again.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Switch: a read-only Switch inside a switch row still renders role="switch", so web reports nested interactive controls

1 participant