Skip to content

Commit

Permalink
feat: Add aria-hidden prop to Pressable and Touchables components
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrieldonadel committed Sep 5, 2022
1 parent 2560bd5 commit a2121a2
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 11 deletions.
5 changes: 5 additions & 0 deletions Libraries/Components/Pressable/Pressable.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ type Props = $ReadOnly<{|
accessibilityValue?: ?AccessibilityValue,
accessibilityViewIsModal?: ?boolean,
accessible?: ?boolean,
/**
* A value indicating whether the accessibility elements contained within
* this accessibility element are hidden.
*/
'aria-hidden'?: ?boolean,
focusable?: ?boolean,
importantForAccessibility?: ?('auto' | 'yes' | 'no' | 'no-hide-descendants'),
onAccessibilityAction?: ?(event: AccessibilityActionEvent) => mixed,
Expand Down
10 changes: 8 additions & 2 deletions Libraries/Components/Touchable/TouchableBounce.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,16 @@ class TouchableBounce extends React.Component<Props, State> {
accessibilityActions={this.props.accessibilityActions}
onAccessibilityAction={this.props.onAccessibilityAction}
accessibilityValue={this.props.accessibilityValue}
importantForAccessibility={this.props.importantForAccessibility}
importantForAccessibility={
this.props['aria-hidden'] === true
? 'no-hide-descendants'
: this.props.importantForAccessibility
}
accessibilityLiveRegion={this.props.accessibilityLiveRegion}
accessibilityViewIsModal={this.props.accessibilityViewIsModal}
accessibilityElementsHidden={this.props.accessibilityElementsHidden}
accessibilityElementsHidden={
this.props['aria-hidden'] ?? this.props.accessibilityElementsHidden
}
nativeID={this.props.nativeID}
testID={this.props.testID}
hitSlop={this.props.hitSlop}
Expand Down
10 changes: 8 additions & 2 deletions Libraries/Components/Touchable/TouchableHighlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,16 @@ class TouchableHighlight extends React.Component<Props, State> {
accessibilityValue={this.props.accessibilityValue}
accessibilityActions={this.props.accessibilityActions}
onAccessibilityAction={this.props.onAccessibilityAction}
importantForAccessibility={this.props.importantForAccessibility}
importantForAccessibility={
this.props['aria-hidden'] === true
? 'no-hide-descendants'
: this.props.importantForAccessibility
}
accessibilityLiveRegion={this.props.accessibilityLiveRegion}
accessibilityViewIsModal={this.props.accessibilityViewIsModal}
accessibilityElementsHidden={this.props.accessibilityElementsHidden}
accessibilityElementsHidden={
this.props['aria-hidden'] ?? this.props.accessibilityElementsHidden
}
style={StyleSheet.compose(
this.props.style,
this.state.extraStyles?.underlay,
Expand Down
8 changes: 6 additions & 2 deletions Libraries/Components/Touchable/TouchableNativeFeedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,14 @@ class TouchableNativeFeedback extends React.Component<Props, State> {
accessibilityActions: this.props.accessibilityActions,
onAccessibilityAction: this.props.onAccessibilityAction,
accessibilityValue: this.props.accessibilityValue,
importantForAccessibility: this.props.importantForAccessibility,
importantForAccessibility:
this.props['aria-hidden'] === true
? 'no-hide-descendants'
: this.props.importantForAccessibility,
accessibilityLiveRegion: this.props.accessibilityLiveRegion,
accessibilityViewIsModal: this.props.accessibilityViewIsModal,
accessibilityElementsHidden: this.props.accessibilityElementsHidden,
accessibilityElementsHidden:
this.props['aria-hidden'] ?? this.props.accessibilityElementsHidden,
hasTVPreferredFocus: this.props.hasTVPreferredFocus,
hitSlop: this.props.hitSlop,
focusable:
Expand Down
10 changes: 8 additions & 2 deletions Libraries/Components/Touchable/TouchableOpacity.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,16 @@ class TouchableOpacity extends React.Component<Props, State> {
accessibilityActions={this.props.accessibilityActions}
onAccessibilityAction={this.props.onAccessibilityAction}
accessibilityValue={this.props.accessibilityValue}
importantForAccessibility={this.props.importantForAccessibility}
importantForAccessibility={
this.props['aria-hidden'] === true
? 'no-hide-descendants'
: this.props.importantForAccessibility
}
accessibilityLiveRegion={this.props.accessibilityLiveRegion}
accessibilityViewIsModal={this.props.accessibilityViewIsModal}
accessibilityElementsHidden={this.props.accessibilityElementsHidden}
accessibilityElementsHidden={
this.props['aria-hidden'] ?? this.props.accessibilityElementsHidden
}
style={[this.props.style, {opacity: this.state.anim}]}
nativeID={this.props.nativeID}
testID={this.props.testID}
Expand Down
10 changes: 8 additions & 2 deletions Libraries/Components/Touchable/TouchableWithoutFeedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type Props = $ReadOnly<{|
accessibilityValue?: ?AccessibilityValue,
accessibilityViewIsModal?: ?boolean,
accessible?: ?boolean,
'aria-hidden'?: ?boolean,
children?: ?React.Node,
delayLongPress?: ?number,
delayPressIn?: ?number,
Expand Down Expand Up @@ -71,7 +72,6 @@ type State = $ReadOnly<{|

const PASSTHROUGH_PROPS = [
'accessibilityActions',
'accessibilityElementsHidden',
'accessibilityHint',
'accessibilityLanguage',
'accessibilityIgnoresInvertColors',
Expand All @@ -81,7 +81,6 @@ const PASSTHROUGH_PROPS = [
'accessibilityValue',
'accessibilityViewIsModal',
'hitSlop',
'importantForAccessibility',
'nativeID',
'onAccessibilityAction',
'onBlur',
Expand Down Expand Up @@ -123,6 +122,13 @@ class TouchableWithoutFeedback extends React.Component<Props, State> {
: this.props.accessibilityState,
focusable:
this.props.focusable !== false && this.props.onPress !== undefined,

accessibilityElementsHidden:
this.props['aria-hidden'] ?? this.props.accessibilityElementsHidden,
importantForAccessibility:
this.props['aria-hidden'] === true
? 'no-hide-descendants'
: this.props.importantForAccessibility,
};
for (const prop of PASSTHROUGH_PROPS) {
if (this.props[prop] !== undefined) {
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Components/View/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ const View: React.AbstractComponent<
ariaHidden ?? accessibilityElementsHidden
}
importantForAccessibility={
ariaHidden !== undefined
ariaHidden === true
? 'no-hide-descendants'
: importantForAccessibility
}
Expand Down

0 comments on commit a2121a2

Please sign in to comment.