Simplify aria menu item roles/selectors

pull/21833/head
Michael Telatynski 2021-10-06 16:49:53 +01:00
parent a6c780674a
commit b373b98d48
1 changed files with 2 additions and 5 deletions

View File

@ -44,9 +44,6 @@ function getOrCreateContainer(): HTMLDivElement {
return container; return container;
} }
const ARIA_MENU_ITEM_ROLES = new Set(["menuitem", "menuitemcheckbox", "menuitemradio"]);
const ARIA_MENU_ITEM_SELECTOR = '[role^="menuitem"], [role^="menuitemcheckbox"], [role^="menuitemradio"]';
export interface IPosition { export interface IPosition {
top?: number; top?: number;
bottom?: number; bottom?: number;
@ -117,7 +114,7 @@ export class ContextMenu extends React.PureComponent<IProps, IState> {
// We don't need to clean up when unmounting, so ignore // We don't need to clean up when unmounting, so ignore
if (!element) return; if (!element) return;
const first = element.querySelector<HTMLElement>(ARIA_MENU_ITEM_SELECTOR) const first = element.querySelector<HTMLElement>('[role^="menuitem"]')
|| element.querySelector<HTMLElement>('[tab-index]'); || element.querySelector<HTMLElement>('[tab-index]');
if (first) { if (first) {
@ -196,7 +193,7 @@ export class ContextMenu extends React.PureComponent<IProps, IState> {
descending = true; descending = true;
} }
} }
} while (element && !ARIA_MENU_ITEM_ROLES.has(element.getAttribute("role"))); } while (element && !element.getAttribute("role")?.startsWith("menuitem"));
if (element) { if (element) {
(element as HTMLElement).focus(); (element as HTMLElement).focus();