Skip to content

fix(button): apply accessibility props and loading to the pressable - #5225

Open
datsiuk-ck wants to merge 1 commit into
callstack:mainfrom
datsiuk-ck:fix/button-a11y-props
Open

datsiuk-ck wants to merge 1 commit into
callstack:mainfrom
datsiuk-ck:fix/button-a11y-props

Conversation

@datsiuk-ck

Copy link
Copy Markdown

Motivation

Button passes every prop it doesn't name to its outer Surface, so accessibilityLabel, accessibilityState, accessibilityRole and the aria-* states never reached the Pressable that screen readers treat as the button. A loading button wasn't busy either: its spinner was a separate busy progress element. With the issue's repro, the button was read as "Save", with no expanded or busy state.

This PR:

  • Passes accessibilityLabel, accessibilityState, accessibilityRole, aria-busy, aria-checked and aria-selected to the pressable, as fix(button): forward expanded state to the interactive control #5148 did for aria-expanded. State fields go out as aria-* props, since react-native-web ignores accessibilityState.
  • Marks a loading button busy and hides its ActivityIndicator from assistive technology (aria-hidden).
  • Lets accessibilityRole replace the default role="button", so accessibilityRole="link" gives one link instead of a link around a button.
  • On Android, labels a busy button without a label by its text. React Native writes "busy" into the content description, which TalkBack reads instead of the text, so <Button loading>Uploading</Button> would otherwise be read as "busy. Button".
  • Removes Button from the migration guide's list of components that pass these props to their outer container.

Related issue

Closes #5216. Unlike #5217, this also keeps the name of a loading button without a label on Android, and covers the aria-* states and accessibilityRole.

Screenshots / Videos

Before After
Android, issue repro "Save. Button" + "busy. Progress Bar" imageimage "collapsed. Save draft, busy. Button" image
Android, loading, no label "Uploading. Button" + "busy. Progress Bar" imageimage "Uploading, busy. Button" image
iOS, issue repro Button "Save", no value image Button "Save draft", value "busy" image
Web, issue repro button "Save" inside generic "Save draft", plus a progressbar image button "Save draft", expanded: false, busy image

Test plan

Checked with main and this branch side by side (Expo 58, React Native 0.88.1): Android emulator with TalkBack, iOS simulator with Accessibility Inspector, Chrome.

  1. Issue repro, <Button accessibilityLabel="Save draft" accessibilityState={{ expanded: false }} loading>Save</Button>: one item on every platform, named "Save draft", busy (and collapsed on Android and web). TalkBack swipes past it with no progress bar item.
  2. <Button loading>Uploading {3} files</Button> on Android: "Uploading 3 files, busy. Button".
  3. accessibilityRole="link": one link (TalkBack "Open docs. Link").
  4. aria-busy / aria-selected: on the button itself ("Syncing, busy", "selected. Inbox").
  5. disabled, toggle, icon and plain buttons: unchanged.

Unit tests cover each case.

Known limitation: on Android, a loading button whose content isn't plain text (e.g. <Trans>) keeps its name but isn't announced as busy.

@github-actions

Copy link
Copy Markdown

Found potential problems with the pull request:

  • The description is too long. Please keep it under 1000 characters.

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.

Button: accessibilityLabel, accessibilityState and loading state don't reach the pressable

1 participant