Skip to content

Commit 7775b3a

Browse files
committed
[change] Remove special treatment of accessibilityRole="menuitem"
This role is not meant to be in the tab flow unless the element type demands it. Users will now have to manage `onClick` and `onKeyDown` callbacks to apply the desired interaction behavior. Fix necolas#1968
1 parent 22f3d14 commit 7775b3a

File tree

6 files changed

+4
-42
lines changed

6 files changed

+4
-42
lines changed

packages/docs/src/pages/docs/components/text-input.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ Equivalent to [HTMLElement.readonly](https://developer.mozilla.org/en-US/docs/We
8484
{% endcall %}
8585

8686
{% call macro.prop('keyboardType', '?string') %}
87-
Hints at the type of data that might be entered by the user while editing the element or its contents. Equivalent to [HTMLElement.inputMode](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/inputmode). Safari iOS requires an ancestral <form action> element to display the search keyboard. (Not available when multiline is true.)
87+
Hints at the type of data that might be entered by the user while editing the element or its contents. Equivalent to [HTMLElement.inputMode](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/inputmode). Safari iOS requires an ancestral `<form action>` element to display the search keyboard. (Not available when multiline is true.)
8888
{% endcall %}
8989

9090
{% call macro.prop('lang', '?string') %}

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

Lines changed: 0 additions & 19 deletions
This file was deleted.

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@
77
* @flow
88
*/
99

10-
import buttonLikeRoles from './buttonLikeRoles';
1110
import isDisabled from './isDisabled';
1211
import propsToAccessibilityComponent from './propsToAccessibilityComponent';
1312
import propsToAriaRole from './propsToAriaRole';
1413

1514
const AccessibilityUtil = {
16-
buttonLikeRoles,
1715
isDisabled,
1816
propsToAccessibilityComponent,
1917
propsToAriaRole

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,6 @@ describe('modules/createDOMProps', () => {
8080
testFocusableRole('button');
8181
});
8282

83-
describe('"accessibilityRole" of "menuitem"', () => {
84-
testFocusableRole('menuitem');
85-
});
86-
8783
describe('with unfocusable accessibilityRole', () => {
8884
test('when "focusable" is true', () => {
8985
expect(createProps({ focusable: true })).toEqual(
@@ -116,7 +112,6 @@ describe('modules/createDOMProps', () => {
116112
expect(callsOnClick('div', 'link')).toBe(true);
117113
expect(callsOnClick('div', 'button')).toBe(true);
118114
expect(callsOnClick('div', 'textbox')).toBe(true);
119-
expect(callsOnClick('div', 'menuitem')).toBe(true);
120115
expect(callsOnClick('div', 'bogus')).toBe(true);
121116
expect(callsOnClick('a')).toBe(true);
122117
expect(callsOnClick('button')).toBe(true);
@@ -129,7 +124,6 @@ describe('modules/createDOMProps', () => {
129124
test('is not called when disabled is true', () => {
130125
expect(callsOnClick('div', 'link', true)).toBe(false);
131126
expect(callsOnClick('div', 'button', true)).toBe(false);
132-
expect(callsOnClick('div', 'menuitem', true)).toBe(false);
133127
expect(callsOnClick('a', undefined, true)).toBe(false);
134128
expect(callsOnClick('button', undefined, true)).toBe(false);
135129
expect(callsOnClick('input', undefined, true)).toBe(false);
@@ -166,7 +160,6 @@ describe('modules/createDOMProps', () => {
166160
expect(respondsToEnter('div', 'link', true)).toBe(false);
167161
expect(respondsToEnter('div', 'button', true)).toBe(false);
168162
expect(respondsToEnter('div', 'textbox', true)).toBe(false);
169-
expect(respondsToEnter('div', 'menuitem', true)).toBe(false);
170163
expect(respondsToEnter('div', 'bogus', true)).toBe(false);
171164
});
172165

@@ -190,7 +183,6 @@ describe('modules/createDOMProps', () => {
190183

191184
test('emulates "onClick" for "Enter" for certain roles', () => {
192185
expect(respondsToEnter('div', 'button')).toBe(true);
193-
expect(respondsToEnter('div', 'menuitem')).toBe(true);
194186
expect(respondsToEnter('div', 'textbox')).toBe(false);
195187
expect(respondsToEnter('div', 'bogus')).toBe(false);
196188
});
@@ -209,7 +201,6 @@ describe('modules/createDOMProps', () => {
209201

210202
test('emulates "onClick" for "Space" for certain roles', () => {
211203
expect(respondsToSpace('div', 'button')).toBe(true);
212-
expect(respondsToSpace('div', 'menuitem')).toBe(true);
213204
expect(respondsToSpace('div', 'textbox')).toBe(false);
214205
expect(respondsToSpace('div', 'bogus')).toBe(false);
215206
});

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,6 @@ const createDOMProps = (elementType, props) => {
365365
role === 'button' ||
366366
role === 'checkbox' ||
367367
role === 'link' ||
368-
role === 'menuitem' ||
369368
role === 'radio' ||
370369
role === 'textbox' ||
371370
role === 'switch'
@@ -421,12 +420,7 @@ const createDOMProps = (elementType, props) => {
421420
// Keyboard accessibility
422421
// Button-like roles should trigger 'onClick' if SPACE key is pressed.
423422
// Button-like roles should not trigger 'onClick' if they are disabled.
424-
if (
425-
isNativeInteractiveElement ||
426-
role === 'button' ||
427-
role === 'menuitem' ||
428-
(_focusable === true && !disabled)
429-
) {
423+
if (isNativeInteractiveElement || role === 'button' || (_focusable === true && !disabled)) {
430424
const onClick = domProps.onClick;
431425
if (onClick != null) {
432426
if (disabled) {
@@ -441,7 +435,7 @@ const createDOMProps = (elementType, props) => {
441435
domProps.onKeyDown = function (e) {
442436
const { key, repeat } = e;
443437
const isSpacebarKey = key === ' ' || key === 'Spacebar';
444-
const isButtonRole = role === 'button' || role === 'menuitem';
438+
const isButtonRole = role === 'button';
445439
if (onKeyDown != null) {
446440
onKeyDown(e);
447441
}

packages/react-native-web/src/modules/usePressEvents/PressResponder.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,7 @@ const isValidKeyPress = (event) => {
134134
const target = event.currentTarget;
135135
const role = target.getAttribute('role');
136136
const isSpacebar = key === ' ' || key === 'Spacebar';
137-
return (
138-
!event.repeat && (key === 'Enter' || (isSpacebar && (role === 'button' || role === 'menuitem')))
139-
);
137+
return !event.repeat && (key === 'Enter' || (isSpacebar && role === 'button'));
140138
};
141139

142140
const DEFAULT_LONG_PRESS_DELAY_MS = 450; // 500 - 50

0 commit comments

Comments
 (0)