Skip to content

Commit ae94551

Browse files
committed
[change] Remove accessibilityTraits and accessibilityComponentType props
These props are deprecated in React Native and replaced by accessibilityRole Ref #1352
1 parent 1af0218 commit ae94551

File tree

13 files changed

+11
-97
lines changed

13 files changed

+11
-97
lines changed

docs/guides/accessibility.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,7 @@ announce text in the `Text` view because of its
6767

6868
In some cases, we also want to alert the end user of the type of selected
6969
component (i.e., that it is a “button”). To provide more context to screen
70-
readers on the web, you should use the `accessibilityRole` property. (Note that
71-
React Native for Web also provides a compatibility mapping of equivalent
72-
`accessibilityTraits` and `accessibilityComponentType` values to
73-
`accessibilityRole`).
70+
readers on the web, you should use the `accessibilityRole` property.
7471

7572
The `accessibilityRole` prop is used to infer an [analogous HTML
7673
element][html-aria-url] and ARIA `role`, where possible. In most cases, both

packages/react-native-web/src/exports/Text/TextPropTypes.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@
1010

1111
import StyleSheetPropType from '../../modules/StyleSheetPropType';
1212
import TextStylePropTypes from './TextStylePropTypes';
13-
import { any, array, bool, func, number, oneOf, oneOfType, string } from 'prop-types';
13+
import { any, bool, func, number, oneOf, string } from 'prop-types';
1414

1515
const TextPropTypes = {
16-
accessibilityComponentType: string,
1716
accessibilityLabel: string,
1817
accessibilityLiveRegion: oneOf(['assertive', 'none', 'polite']),
1918
accessibilityRole: oneOf([
@@ -26,7 +25,6 @@ const TextPropTypes = {
2625
'none',
2726
'text'
2827
]),
29-
accessibilityTraits: oneOfType([array, string]),
3028
accessible: bool,
3129
children: any,
3230
importantForAccessibility: oneOf(['auto', 'no', 'no-hide-descendants', 'yes']),

packages/react-native-web/src/exports/TouchableWithoutFeedback/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,8 @@ const TouchableWithoutFeedback = createReactClass({
3737
mixins: [TimerMixin, Touchable.Mixin],
3838

3939
propTypes: {
40-
accessibilityComponentType: ViewPropTypes.accessibilityComponentType,
4140
accessibilityLabel: string,
4241
accessibilityRole: ViewPropTypes.accessibilityRole,
43-
accessibilityTraits: ViewPropTypes.accessibilityTraits,
4442
accessible: bool,
4543
children: any,
4644
/**

packages/react-native-web/src/exports/View/ViewPropTypes.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import EdgeInsetsPropType, { type EdgeInsetsProp } from '../EdgeInsetsPropType';
1212
import StyleSheetPropType from '../../modules/StyleSheetPropType';
1313
import ViewStylePropTypes from './ViewStylePropTypes';
14-
import { any, array, arrayOf, bool, func, object, oneOf, oneOfType, string } from 'prop-types';
14+
import { any, arrayOf, bool, func, object, oneOf, string } from 'prop-types';
1515
import { type StyleObj } from '../StyleSheet/StyleSheetTypes';
1616

1717
const stylePropType = StyleSheetPropType(ViewStylePropTypes);
@@ -35,7 +35,6 @@ export type ViewProps = {
3535
accessibilityLiveRegion?: 'none' | 'polite' | 'assertive',
3636
accessibilityRole?: string,
3737
accessibilityStates?: Array<string>,
38-
accessibilityTraits?: string | Array<string>,
3938
accessible?: boolean,
4039
children?: any,
4140
className?: string,
@@ -105,7 +104,6 @@ const ViewPropTypes = {
105104
'pressed'
106105
])
107106
),
108-
accessibilityTraits: oneOfType([array, string]),
109107
accessible: bool,
110108
children: any,
111109
hitSlop: EdgeInsetsPropType,

packages/react-native-web/src/exports/View/filterSupportedProps.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@
88
*/
99

1010
const supportedProps = {
11-
accessibilityComponentType: true,
1211
accessibilityLabel: true,
1312
accessibilityLiveRegion: true,
1413
accessibilityRole: true,
1514
accessibilityStates: true,
16-
accessibilityTraits: true,
1715
accessible: true,
1816
children: true,
1917
disabled: true,

packages/react-native-web/src/modules/AccessibilityUtil/__tests__/propsToAriaRole-test.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,6 @@ describe('modules/AccessibilityUtil/propsToAriaRole', () => {
1111
expect(propsToAriaRole({ accessibilityRole: 'banner' })).toEqual('banner');
1212
});
1313

14-
test('when iOS/Android accessibility prop equals "button"', () => {
15-
expect(propsToAriaRole({ accessibilityComponentType: 'button' })).toEqual('button');
16-
expect(propsToAriaRole({ accessibilityTraits: 'button' })).toEqual('button');
17-
});
18-
19-
test('prioritizes "accessibilityRole" when defined', () => {
20-
expect(
21-
propsToAriaRole({
22-
accessibilityComponentType: 'button',
23-
accessibilityRole: 'link',
24-
accessibilityTraits: 'button'
25-
})
26-
).toEqual('link');
27-
});
28-
2914
test('when "accessibilityRole" is a native-only value', () => {
3015
expect(propsToAriaRole({ accessibilityRole: 'none' })).toEqual('presentation');
3116
expect(propsToAriaRole({ accessibilityRole: 'imagebutton' })).toEqual(undefined);

packages/react-native-web/src/modules/AccessibilityUtil/propsToAriaRole.js

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,6 @@
77
* @flow
88
*/
99

10-
const accessibilityComponentTypeToRole = {
11-
button: 'button',
12-
none: 'presentation'
13-
};
14-
15-
const accessibilityTraitsToRole = {
16-
adjustable: 'slider',
17-
button: 'button',
18-
header: 'heading',
19-
image: 'img',
20-
link: 'link',
21-
none: 'presentation',
22-
search: 'search',
23-
summary: 'region'
24-
};
25-
2610
const accessibilityRoleToWebRole = {
2711
adjustable: 'slider',
2812
button: 'button',
@@ -38,30 +22,14 @@ const accessibilityRoleToWebRole = {
3822
text: null
3923
};
4024

41-
/**
42-
* Provides compatibility with React Native's "accessibilityTraits" (iOS) and
43-
* "accessibilityComponentType" (Android), converting them to equivalent ARIA
44-
* roles.
45-
*/
46-
const propsToAriaRole = ({
47-
accessibilityComponentType,
48-
accessibilityRole,
49-
accessibilityTraits
50-
}: Object) => {
25+
const propsToAriaRole = ({ accessibilityRole }: Object) => {
5126
if (accessibilityRole) {
5227
const inferredRole = accessibilityRoleToWebRole[accessibilityRole];
5328
if (inferredRole !== null) {
5429
// ignore roles that don't map to web
5530
return inferredRole || accessibilityRole;
5631
}
5732
}
58-
if (accessibilityTraits) {
59-
const trait = Array.isArray(accessibilityTraits) ? accessibilityTraits[0] : accessibilityTraits;
60-
return accessibilityTraitsToRole[trait];
61-
}
62-
if (accessibilityComponentType) {
63-
return accessibilityComponentTypeToRole[accessibilityComponentType];
64-
}
6533
};
6634

6735
export default propsToAriaRole;

packages/react-native-web/src/modules/createDOMProps/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ const createDOMProps = (component, props, styleResolver) => {
7474
testID,
7575
/* eslint-disable */
7676
accessible,
77-
accessibilityComponentType,
7877
accessibilityRole,
79-
accessibilityTraits,
8078
/* eslint-enable */
8179
...domProps
8280
} = props;

packages/website/storybook/1-components/Text/TextScreen.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@ const TextScreen = () => (
6868
Allows assistive technologies to present and support interaction with the view in a
6969
manner that is consistent with user expectations for similar views of that type. For
7070
example, marking a touchable view with an <Code>accessibilityRole</Code> of{' '}
71-
<Code>button</Code>. For compatibility with React Native{' '}
72-
<Code>accessibilityTraits</Code> and <Code>accessibilityComponentType</Code> are mapped
73-
to <Code>accessibilityRole</Code>. (This is implemented using ARIA roles.)
71+
<Code>button</Code>. (This is implemented using ARIA roles.)
7472
</AppText>
7573
}
7674
/>

packages/website/storybook/1-components/View/ViewScreen.js

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ const ViewScreen = () => (
6464
Allows assistive technologies to present and support interaction with the view in a
6565
manner that is consistent with user expectations for similar views of that type. For
6666
example, marking a touchable view with an <Code>accessibilityRole</Code> of{' '}
67-
<Code>button</Code>. For compatibility with React Native{' '}
68-
<Code>accessibilityTraits</Code> and <Code>accessibilityComponentType</Code> are mapped
69-
to <Code>accessibilityRole</Code>. (This is implemented using ARIA roles.)
67+
<Code>button</Code>. (This is implemented using ARIA roles.)
7068
</AppText>
7169
}
7270
/>
@@ -268,28 +266,6 @@ const ViewScreen = () => (
268266
typeInfo="?string"
269267
description="Used to locate this view in end-to-end tests. The test ID is rendered to a 'data-testid' DOM attribute"
270268
/>
271-
272-
<DocItem
273-
label="compat"
274-
name="accessibilityComponentType"
275-
typeInfo="?enum(roles)"
276-
description={
277-
<AppText>
278-
(For compatibility with React Native. Equivalent to <Code>accessibilityRole</Code>.)
279-
</AppText>
280-
}
281-
/>
282-
283-
<DocItem
284-
label="compat"
285-
name="accessibilityTraits"
286-
typeInfo="?enum(roles) | Array<role>"
287-
description={
288-
<AppText>
289-
(For compatibility with React Native. Equivalent to <Code>accessibilityRole</Code>.)
290-
</AppText>
291-
}
292-
/>
293269
</Section>
294270

295271
<Section title="More examples">

0 commit comments

Comments
 (0)