Skip to content

Commit 7b2d817

Browse files
fabOnReactfacebook-github-bot
authored andcommitted
Text Component does not announce disabled and disables click functionality when disabled (#33076)
Summary: This issue fixes #30937 fixes #30947 fixes #30840 ([Test Case 7.1][7.1], [Test Case 7.3][7.3], [Test Case 7.5][7.5]) . The issue is caused by: 1) The missing javascript logic on the `accessibilityState` in the Text component fabOnReact@6ab7ab3 (as previously implemented in [Button][20]). 2) The missing setter for prop `accessible` in `ReactTextAnchorViewManager` fabOnReact@17095c6 (More information in previous PR #31252) Related PR #33070 PR callstack/react-native-slider#354 [20]: https://github.com/facebook/react-native/pull/31001/files#diff-4f225d043edf4cf5b8288285b6a957e2187fc0242f240bde396e41c4c25e4124R281-R289 ## Changelog [Android] [Fixed] - Text Component does not announce disabled and disables click functionality when disabled Pull Request resolved: #33076 Test Plan: [1]. Text has `disabled` and `accessibilityState={{disabled: false}}` ([link][1]) [2]. Text has `disabled` ([link][2]) [3]. Text has `accessibilityState={{disabled: true}}` ([link][3]) [4]. Text has `accessibilityState={{disabled:false}}` ([link][4]) [5]. Text has `disabled={false}` and `accessibilityState={{disabled:true}}` ([link][5]) [6]. Text has `accessibilityState={{disabled:true}}` and method `setAccessible` in `ReactTextAnchorViewManager` (tested on commit [b4cd8][10]) ([link][6]) 7. Test Cases on the main branch [7.1]. Text has `disabled` and `accessibilityState={{disabled: false}}` ([link][7.1]) [7.3] Text has `accessibilityState={{disabled: true}}` ([link][7.3]) [7.5] Text has `disabled={false}` and `accessibilityState={{disabled:true}}` ([link][7.5]) [7.6] Text has `onPress callback` and `accessibilityState={{disabled: true}}` ([link][7.6]) [7.7] Text has `accessibilityState={{disabled:true}}` and no method `setAccessible` in `ReactTextAnchorViewManager` (tested on commit [c4f98dd][11]) ([link][7.7]) [1]: fabOnReact/react-native-notes#1 (comment) [2]: fabOnReact/react-native-notes#1 (comment) [3]: fabOnReact/react-native-notes#1 (comment) [4]: fabOnReact/react-native-notes#1 (comment) [5]: fabOnReact/react-native-notes#1 (comment) [6]: fabOnReact/react-native-notes#1 (comment) [7.1]: fabOnReact/react-native-notes#1 (comment) [7.3]: fabOnReact/react-native-notes#1 (comment) [7.5]: fabOnReact/react-native-notes#1 (comment) [7.6]: fabOnReact/react-native-notes#1 (comment) [7.7]: fabOnReact/react-native-notes#1 (comment) [10]: 17095c6 [11]: 6ab7ab3 Reviewed By: blavalla Differential Revision: D34211793 Pulled By: ShikaSD fbshipit-source-id: e153fb48c194f5884e30beb9172e66aca7ce1a41
1 parent 370c65b commit 7b2d817

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

Libraries/Text/Text.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,20 @@ const Text: React.AbstractComponent<
4848

4949
const [isHighlighted, setHighlighted] = useState(false);
5050

51+
const _disabled =
52+
restProps.disabled != null
53+
? restProps.disabled
54+
: props.accessibilityState?.disabled;
55+
const _accessibilityState =
56+
_disabled !== props.accessibilityState?.disabled
57+
? {...props.accessibilityState, disabled: _disabled}
58+
: props.accessibilityState;
59+
5160
const isPressable =
5261
(onPress != null ||
5362
onLongPress != null ||
5463
onStartShouldSetResponder != null) &&
55-
restProps.disabled !== true;
64+
_disabled !== true;
5665

5766
const initialized = useLazyInitialization(isPressable);
5867
const config = useMemo(
@@ -174,7 +183,9 @@ const Text: React.AbstractComponent<
174183
<NativeText
175184
{...restProps}
176185
{...eventHandlersForText}
186+
disabled={_disabled}
177187
accessible={accessible !== false}
188+
accessibilityState={_accessibilityState}
178189
allowFontScaling={allowFontScaling !== false}
179190
ellipsizeMode={ellipsizeMode ?? 'tail'}
180191
isHighlighted={isHighlighted}

ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextAnchorViewManager.java

+5
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ public abstract class ReactTextAnchorViewManager<T extends View, C extends React
4343
};
4444
private static final String TAG = "ReactTextAnchorViewManager";
4545

46+
@ReactProp(name = "accessible")
47+
public void setAccessible(ReactTextView view, boolean accessible) {
48+
view.setFocusable(accessible);
49+
}
50+
4651
// maxLines can only be set in master view (block), doesn't really make sense to set in a span
4752
@ReactProp(name = ViewProps.NUMBER_OF_LINES, defaultInt = ViewDefaults.NUMBER_OF_LINES)
4853
public void setNumberOfLines(ReactTextView view, int numberOfLines) {

0 commit comments

Comments
 (0)