Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 25.2k
Added talkback support for button accessibility: disabled prop#31001
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
599cd817266305eb7bda3eb3c9a00024420db1644fd3fcdb623a1f9be0ece83b499b2f7e6dfc8c25f8e8File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -18,7 +18,7 @@ const Text = require('../Text/Text'); | ||
| const TouchableNativeFeedback = require('./Touchable/TouchableNativeFeedback'); | ||
| const TouchableOpacity = require('./Touchable/TouchableOpacity'); | ||
| const View = require('./View/View'); | ||
| import type {AccessibilityState} from './View/ViewAccessibility'; | ||
| const invariant = require('invariant'); | ||
| import type {PressEvent} from '../Types/CoreEventTypes'; | ||
| @@ -134,6 +134,11 @@ type ButtonProps = $ReadOnly<{| | ||
| Used to locate this view in end-to-end tests. | ||
| */ | ||
| testID?: ?string, | ||
| /** | ||
| * Accessibility props. | ||
| */ | ||
| accessibilityState?: ?AccessibilityState, | ||
| |}>; | ||
| /** | ||
| @@ -261,7 +266,6 @@ class Button extends React.Component<ButtonProps> { | ||
| nextFocusLeft, | ||
| nextFocusRight, | ||
| nextFocusUp, | ||
| disabled, | ||
| testID, | ||
| } = this.props; | ||
| const buttonStyles = [styles.button]; | ||
| @@ -273,12 +277,22 @@ class Button extends React.Component<ButtonProps> { | ||
| buttonStyles.push({backgroundColor: color}); | ||
| } | ||
| } | ||
| const accessibilityState = {}; | ||
| const disabled = | ||
| this.props.disabled != null | ||
| ? this.props.disabled | ||
| : this.props.accessibilityState?.disabled; | ||
| const accessibilityState = | ||
| disabled !== this.props.accessibilityState?.disabled | ||
| ? {...this.props.accessibilityState, disabled} | ||
| : this.props.accessibilityState; | ||
| if (disabled) { | ||
| buttonStyles.push(styles.buttonDisabled); | ||
| textStyles.push(styles.textDisabled); | ||
| accessibilityState.disabled = true; | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kacieb brought up a great point -- this PR doesn't seem to be fixing accessibility for talkback but rather adding an ability for accessibilityState -- I tested on an Android device and did notice that talkback does announce "disabled" for the button in your example where you solely use That raises the question of what was the original issue reporting? Was it reporting that Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cc @blavalla who reported the issue for clarification -- relevant to our discussion on disabled vs. accessibilityState.disabled Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm going to hold off landing this PR until we have some clarity about what the original issue is. Author There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Noted! Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lunaleaps, the original issue was that setting This snack (https://snack.expo.io/d1Ikg7nqo) from #30840 shows the issue well. Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To clarify further, the issue was mostly that it is weird that you can actually set conflicting states for accessibility and non-accessibility users. Basically, there is nothing stopping someone from setting If we are going to explicitly allow this though, they should at least work as expected, with the accessibilityState: disabled actually disabling the element for accessibility users.
| ||
| } | ||
| invariant( | ||
| typeof title === 'string', | ||
| 'The title prop of a Button must be a string', | ||
| @@ -287,6 +301,7 @@ class Button extends React.Component<ButtonProps> { | ||
| Platform.OS === 'android' ? title.toUpperCase() : title; | ||
| const Touchable = | ||
| Platform.OS === 'android' ? TouchableNativeFeedback : TouchableOpacity; | ||
| return ( | ||
| <Touchable | ||
| accessibilityLabel={accessibilityLabel} | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: should this also be grouped with line 24? I can also fix this on import
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this should be grouped with other type imports 💯. Please fix this during import