-
Notifications
You must be signed in to change notification settings - Fork 24.5k
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
Added talkback support for button accessibility: disabled prop #31001
Changes from all commits
599cd81
7266305
eb7bda3
eb3c9a0
0024420
db1644f
d3fcdb6
23a1f9b
e0ece83
b499b2f
7e6dfc8
c25f8e8
File filter
Filter by extension
Conversations
Jump to
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; | ||
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 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 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. 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! 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. 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. 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. Ah right! Edit: Ah right because the snack does not have Flow enabled, it didn't warn by the fact that 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 I explicitly tested Having two different props is confusing. To disable the onPress we have to 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.
Yea I think that's covered by #30943 I think we should set this down for a bit and circle back to how we should handle these two props |
||
} | ||
|
||
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
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