Skip to content

Commit

Permalink
Merge pull request #155 from jpzwarte/fix/delegates-focus-without-foc…
Browse files Browse the repository at this point in the history
…usable-element

Fix incorrect `isFocusable` result for `ShadowRoot`
  • Loading branch information
jgerigmeyer authored Nov 29, 2023
2 parents 45dd419 + 9598985 commit 079f724
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/popover-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ function topMostPopoverAncestor(newPopover: HTMLElement): HTMLElement | null {
}

function isFocusable(focusTarget: HTMLElement) {
if (focusTarget.hidden) return false;
if (focusTarget.hidden || focusTarget instanceof ShadowRoot) return false;
if (
focusTarget instanceof HTMLButtonElement ||
focusTarget instanceof HTMLInputElement ||
Expand All @@ -181,7 +181,9 @@ function isFocusable(focusTarget: HTMLElement) {
if (focusTarget instanceof HTMLAnchorElement && focusTarget.href === '') {
return false;
}
return focusTarget.tabIndex !== -1;
return (
typeof focusTarget.tabIndex === 'number' && focusTarget.tabIndex !== -1
);
}

// This method is not spec compliant, as it also looks in slotted content
Expand Down

0 comments on commit 079f724

Please sign in to comment.