Skip to content

Commit

Permalink
refactor(onToggleArrowKeydownDefault): don't use :has() selector
Browse files Browse the repository at this point in the history
  • Loading branch information
adamviktora committed Nov 20, 2024
1 parent 1ccd782 commit f2ab64a
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions packages/react-core/src/helpers/KeyboardHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,17 +183,17 @@ export const onToggleArrowKeydownDefault = (event: KeyboardEvent, menuRef: React

event.preventDefault();

const interactiveElementSelector = 'button:not(:disabled),input:not(:disabled),a:not([aria-disabled="true"])';
const listItemSelector = `li:has(${interactiveElementSelector})`;
let listItem: Element;
const listItems = Array.from(menuRef.current?.querySelectorAll('li'));
const focusableElements = listItems
.map((li) => li.querySelector('button:not(:disabled),input:not(:disabled),a:not([aria-disabled="true"])'))
.filter((el) => el !== null);

let focusableElement: Element;
if (event.key === 'ArrowDown') {
listItem = menuRef.current?.querySelector(listItemSelector);
focusableElement = focusableElements[0];
} else {
const allItems = menuRef.current?.querySelectorAll(listItemSelector);
listItem = allItems ? allItems[allItems.length - 1] : null;
focusableElement = focusableElements[focusableElements.length - 1];
}

const focusableElement = listItem?.querySelector(interactiveElementSelector);
focusableElement && (focusableElement as HTMLElement).focus();
};

Expand Down

0 comments on commit f2ab64a

Please sign in to comment.