Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/hooks/useAccessibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,16 @@ export const refreshElements = (keys: string[], id: string) => {
const key2element = new Map<string, HTMLElement>();
const element2key = new Map<HTMLElement, string>();

const id2element = new Map<string, HTMLElement>();
document.querySelectorAll<HTMLElement>('[data-menu-id]').forEach(el => {
const menuId = el.getAttribute('data-menu-id');
if (menuId !== null && !id2element.has(menuId)) {
id2element.set(menuId, el);
}
});

keys.forEach(key => {
const element = document.querySelector(`[data-menu-id='${getMenuId(id, key)}']`) as HTMLElement;
const element = id2element.get(getMenuId(id, key));

if (element) {
elements.add(element);
Expand Down
19 changes: 19 additions & 0 deletions tests/Keyboard.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -308,5 +308,24 @@ describe('Menu.Keyboard', () => {
keyDown(container, KeyCode.RIGHT);
isActive(container, 0);
});

it('navigates items whose keys contain quotes, backslashes, or newlines', () => {
const { container } = render(
<Menu mode="inline">
<MenuItem key="men's">Men&apos;s</MenuItem>
<MenuItem key={'C:\\Users\\'}>Windows Path</MenuItem>
<MenuItem key={'line1\nline2'}>Multiline</MenuItem>
</Menu>,
);

keyDown(container, KeyCode.DOWN);
isActive(container, 0);

keyDown(container, KeyCode.DOWN);
isActive(container, 1);

keyDown(container, KeyCode.DOWN);
isActive(container, 2);
});
});
/* eslint-enable */