From 68e5b4ee9f9c5bc4b1b1d38595320054e5b54fd5 Mon Sep 17 00:00:00 2001 From: Fabrizio Cucci Date: Wed, 14 Jan 2026 01:42:12 -0800 Subject: [PATCH] Remove shouldUseLinkRoleForPressableText feature flag (#55121) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/55121 Changelog: [Android][Fixed] - Set accessibilityRole to "link" for pressable Text components by default --- This diff removes the `shouldUseLinkRoleForPressableText` feature flag since it has been tested in FB4A for a month with `defaultValue: true`. The flag was introduced to automatically set `accessibilityRole="link"` for pressable Text components by default. This behavior is now the default. Changes: - Removed the flag definition from `ReactNativeFeatureFlags.config.js` - Removed the conditional checks in `Text.js` (2 locations), now `shouldUseLinkRole` is computed directly without the feature flag - Removed the override from `ReactNativeFeatureFlagsOverrides_Facebook.js` - Updated tests in `Text-test.js` to remove flag mocking and only test the enabled behavior - Regenerated all feature flag files via `js1 featureflags --update` Reviewed By: javache Differential Revision: D90385104 fbshipit-source-id: 2dc0e74209e75c954445434513fbba0f7a97f7af --- packages/react-native/Libraries/Text/Text.js | 10 +- .../Libraries/Text/__tests__/Text-test.js | 358 +++++++----------- .../ReactNativeFeatureFlags.config.js | 10 - .../featureflags/ReactNativeFeatureFlags.js | 8 +- 4 files changed, 132 insertions(+), 254 deletions(-) diff --git a/packages/react-native/Libraries/Text/Text.js b/packages/react-native/Libraries/Text/Text.js index df51994f241..fb5c10b72b7 100644 --- a/packages/react-native/Libraries/Text/Text.js +++ b/packages/react-native/Libraries/Text/Text.js @@ -152,10 +152,7 @@ if (ReactNativeFeatureFlags.reduceDefaultPropsInText()) { _disabled !== true; const shouldUseLinkRole = - ReactNativeFeatureFlags.shouldUseLinkRoleForPressableText() && - isPressable && - accessibilityRole == null && - role == null; + isPressable && accessibilityRole == null && role == null; const _accessibilityRole = accessibilityRole ?? (shouldUseLinkRole ? 'link' : undefined); @@ -420,10 +417,7 @@ if (ReactNativeFeatureFlags.reduceDefaultPropsInText()) { _disabled !== true; const shouldUseLinkRole = - ReactNativeFeatureFlags.shouldUseLinkRoleForPressableText() && - isPressable && - accessibilityRole == null && - role == null; + isPressable && accessibilityRole == null && role == null; const _accessibilityRole = accessibilityRole ?? (shouldUseLinkRole ? 'link' : undefined); diff --git a/packages/react-native/Libraries/Text/__tests__/Text-test.js b/packages/react-native/Libraries/Text/__tests__/Text-test.js index ee81bb1a806..522219e693f 100644 --- a/packages/react-native/Libraries/Text/__tests__/Text-test.js +++ b/packages/react-native/Libraries/Text/__tests__/Text-test.js @@ -12,7 +12,6 @@ import type {ReactTestRendererJSON} from '../../Utilities/ReactNativeTestTools'; import type {ReactTestRenderer} from 'react-test-renderer'; import {create} from '../../../jest/renderer'; -import * as ReactNativeFeatureFlags from '../../../src/private/featureflags/ReactNativeFeatureFlags'; import flattenStyle from '../../StyleSheet/flattenStyle'; import * as React from 'react'; @@ -76,252 +75,153 @@ describe('Text', () => { }); describe('accessibilityRole with onPress/onLongPress', () => { - describe('when shouldUseLinkRoleForPressableText flag is OFF (default)', () => { - beforeEach(() => { - jest - .spyOn(ReactNativeFeatureFlags, 'shouldUseLinkRoleForPressableText') - .mockReturnValue(false); - }); + it('automatically sets accessibilityRole="link" when onPress is provided', async () => { + const instance = await create( + {}}>Clickable Text, + ); - afterEach(() => { - jest.restoreAllMocks(); - }); - - it('does not automatically set accessibilityRole when onPress is provided', async () => { - const instance = await create( - {}}>Clickable Text, - ); - - expect(omitRefAndFlattenStyle(instance)).toMatchInlineSnapshot(` - - Clickable Text - - `); - }); - - it('does not automatically set accessibilityRole when onLongPress is provided', async () => { - const instance = await create( - {}}>Long Press Text, - ); - - expect(omitRefAndFlattenStyle(instance)).toMatchInlineSnapshot(` - - Long Press Text - - `); - }); - - it('does not automatically set accessibilityRole when onStartShouldSetResponder is provided', async () => { - const instance = await create( - true}>Responder Text, - ); - - expect(omitRefAndFlattenStyle(instance)).toMatchInlineSnapshot(` - - Responder Text - - `); - }); - - it('respects explicit accessibilityRole', async () => { - const instance = await create( - {}}> - Explicit Button Role - , - ); - - expect(omitRefAndFlattenStyle(instance)).toMatchInlineSnapshot(` - - Explicit Button Role - - `); - }); + expect(omitRefAndFlattenStyle(instance)).toMatchInlineSnapshot(` + + Clickable Text + + `); }); - describe('when shouldUseLinkRoleForPressableText flag is ON', () => { - beforeEach(() => { - jest - .spyOn(ReactNativeFeatureFlags, 'shouldUseLinkRoleForPressableText') - .mockReturnValue(true); - }); + it('automatically sets accessibilityRole="link" when onLongPress is provided', async () => { + const instance = await create( + {}}>Long Press Text, + ); - afterEach(() => { - jest.restoreAllMocks(); - }); + expect(omitRefAndFlattenStyle(instance)).toMatchInlineSnapshot(` + + Long Press Text + + `); + }); - it('automatically sets accessibilityRole="link" when onPress is provided', async () => { - const instance = await create( - {}}>Clickable Text, - ); + it('automatically sets accessibilityRole="link" when onStartShouldSetResponder is provided', async () => { + const instance = await create( + true}>Responder Text, + ); - expect(omitRefAndFlattenStyle(instance)).toMatchInlineSnapshot(` - - Clickable Text - - `); - }); + expect(omitRefAndFlattenStyle(instance)).toMatchInlineSnapshot(` + + Responder Text + + `); + }); - it('automatically sets accessibilityRole="link" when onLongPress is provided', async () => { - const instance = await create( - {}}>Long Press Text, - ); + it('respects explicit accessibilityRole', async () => { + const instance = await create( + {}}> + Explicit Button Role + , + ); - expect(omitRefAndFlattenStyle(instance)).toMatchInlineSnapshot(` - - Long Press Text - - `); - }); + expect(omitRefAndFlattenStyle(instance)).toMatchInlineSnapshot(` + + Explicit Button Role + + `); + }); - it('automatically sets accessibilityRole="link" when onStartShouldSetResponder is provided', async () => { - const instance = await create( - true}>Responder Text, - ); + it('respects explicit role prop', async () => { + // $FlowFixMe[prop-missing] + const instance = await create( + {}} role="button"> + Explicit Role Prop + , + ); - expect(omitRefAndFlattenStyle(instance)).toMatchInlineSnapshot(` - - Responder Text - - `); - }); + expect(omitRefAndFlattenStyle(instance)).toMatchInlineSnapshot(` + + Explicit Role Prop + + `); + }); - it('respects explicit accessibilityRole', async () => { - const instance = await create( - {}}> - Explicit Button Role - , - ); + it('does not automatically set accessibilityRole when disabled', async () => { + const instance = await create( + {}}> + Disabled Pressable Text + , + ); - expect(omitRefAndFlattenStyle(instance)).toMatchInlineSnapshot(` - - Explicit Button Role - - `); - }); - - it('respects explicit role prop', async () => { - // $FlowFixMe[prop-missing] - const instance = await create( - {}} role="button"> - Explicit Role Prop - , - ); - - expect(omitRefAndFlattenStyle(instance)).toMatchInlineSnapshot(` - - Explicit Role Prop - - `); - }); - - it('does not automatically set accessibilityRole when disabled', async () => { - const instance = await create( - {}}> - Disabled Pressable Text - , - ); - - expect(omitRefAndFlattenStyle(instance)).toMatchInlineSnapshot(` - - Disabled Pressable Text - - `); - }); + } + accessible={true} + allowFontScaling={true} + disabled={true} + ellipsizeMode="tail" + > + Disabled Pressable Text + + `); + }); - it('automatically sets accessibilityRole="link" for nested Text with onPress', async () => { - const instance = await create( - - Parent Text {}}>Nested Clickable Link - , - ); + it('automatically sets accessibilityRole="link" for nested Text with onPress', async () => { + const instance = await create( + + Parent Text {}}>Nested Clickable Link + , + ); - expect(omitRefAndFlattenStyle(instance)).toMatchInlineSnapshot(` + expect(omitRefAndFlattenStyle(instance)).toMatchInlineSnapshot(` + + Parent Text - Parent Text - - Nested Clickable Link - + Nested Clickable Link - `); - }); + + `); }); it('does not set accessibilityRole when no press handlers are provided', async () => { diff --git a/packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js b/packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js index eadb8d2a0ad..501e5c2197b 100644 --- a/packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js +++ b/packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js @@ -980,16 +980,6 @@ const definitions: FeatureFlagDefinitions = { }, ossReleaseStage: 'none', }, - shouldUseLinkRoleForPressableText: { - defaultValue: true, - metadata: { - description: - 'Set accessibilityRole to "link" for pressable Text components by default.', - expectedReleaseValue: true, - purpose: 'release', - }, - ossReleaseStage: 'none', - }, shouldUseRemoveClippedSubviewsAsDefaultOnIOS: { defaultValue: false, metadata: { diff --git a/packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js b/packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js index 5ef19ea424b..be04495dc73 100644 --- a/packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js +++ b/packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<> + * @generated SignedSource<<0acb1755465fae151917d6043a737331>> * @flow strict * @noformat */ @@ -38,7 +38,6 @@ export type ReactNativeFeatureFlagsJsOnly = $ReadOnly<{ reduceDefaultPropsInImage: Getter, reduceDefaultPropsInText: Getter, shouldUseAnimatedObjectForTransform: Getter, - shouldUseLinkRoleForPressableText: Getter, shouldUseRemoveClippedSubviewsAsDefaultOnIOS: Getter, shouldUseSetNativePropsInFabric: Getter, }>; @@ -178,11 +177,6 @@ export const reduceDefaultPropsInText: Getter = createJavaScriptFlagGet */ export const shouldUseAnimatedObjectForTransform: Getter = createJavaScriptFlagGetter('shouldUseAnimatedObjectForTransform', false); -/** - * Set accessibilityRole to "link" for pressable Text components by default. - */ -export const shouldUseLinkRoleForPressableText: Getter = createJavaScriptFlagGetter('shouldUseLinkRoleForPressableText', true); - /** * removeClippedSubviews prop will be used as the default in FlatList on iOS to match Android */