Skip to content

Commit

Permalink
ensure we stop before the body
Browse files Browse the repository at this point in the history
We used to have a `useInertOthers` hook, but it also made everything
inside `document.body` inert. This means that third party packages or
browser extensions that inject something in the `document.body` were
also marked as `inert`. This is something we don't want.

We fixed that previously by introducing a simpler `useInert` where we
explicitly marked certain elements as inert: #2290

But I believe this new implementation is better, especially with this
commit where we stop once we hit `document.body`. This means that we
will never mark `body > *` elements as `inert`.
  • Loading branch information
RobinMalfait committed Apr 24, 2024
1 parent d7c5396 commit 4fdef30
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions packages/@headlessui-react/src/hooks/use-inert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export function useInertOthers(
if (!ownerDocument) continue

let parent = element.parentElement
while (parent) {
while (parent && parent !== ownerDocument.body) {
// Mark all siblings as inert
for (let node of parent.childNodes) {
// If the node contains any of the elements we should not mark it as inert
Expand All @@ -115,9 +115,6 @@ export function useInertOthers(
d.add(markInert(node as HTMLElement))
}

// Stop if we reach the body
if (parent === ownerDocument.body) break

// Move up the tree
parent = parent.parentElement
}
Expand Down

0 comments on commit 4fdef30

Please sign in to comment.