Fix supertab

This commit is contained in:
Jamie Kyle 2024-03-04 12:32:51 -08:00 committed by GitHub
parent 698cd59693
commit e5333546db
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 44 additions and 28 deletions

View file

@ -28,3 +28,17 @@ export const focusableSelectors = [
`[contenteditable]${not.inert}${not.negTabIndex}`,
`[tabindex]${not.inert}${not.negTabIndex}`,
];
export const focusableSelector = focusableSelectors.join(', ');
/**
* Matches the first focusable element within the given element or itself if it
* is focusable.
*/
export function matchOrQueryFocusable(
element: HTMLElement
): HTMLElement | null {
return element.matches(focusableSelector)
? element
: element.querySelector(focusableSelector);
}