Skip to content

Commit

Permalink
Fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
knuton committed Mar 16, 2024
1 parent da52c3d commit 5060c4a
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,31 @@ function isFocusable(element) {
)
return false
// Descends from closed details element
if (
element.closest("details:not([open])") != null &&
(element.tagName !== "SUMMARY" ||
element.parentElement.parentElement.closest("details:not([open])") !=
null)
)
return false
if (hasClosedDetailsAncestor(element)) return false

return true
}

/**
* Tests whether the element is contained within a closed `details` element.
*
* `summary` elements are excluded (return value `false`) if they are the summary of the top-most
* closed `details` element.
*
* @param {Element} element
* @returns {boolean} - True if the element is hidden because of descending from closed `details`
*/
function hasClosedDetailsAncestor(element) {
if (element.parentElement == null) return false

const parentElement = element.parentElement
if (element.tagName === "SUMMARY") {
return hasClosedDetailsAncestor(parentElement)
} else {
return parentElement.closest("details:not([open])") != null
}
}

/**
* Get all candidates for receiving focus when moving from the active element in the given direction.
*
Expand Down

0 comments on commit 5060c4a

Please sign in to comment.