Skip to content

Commit bf7497e

Browse files
committed
cleanup default values for useInertOthers
1 parent b8931b2 commit bf7497e

File tree

1 file changed

+23
-30
lines changed

1 file changed

+23
-30
lines changed

packages/@headlessui-react/src/hooks/use-inert-others.tsx

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,9 @@ function markNotInert(element: HTMLElement) {
7474
*/
7575
export function useInertOthers(
7676
{
77-
allowed,
78-
disallowed,
79-
}: { allowed?: () => (HTMLElement | null)[]; disallowed?: () => (HTMLElement | null)[] } = {
80-
allowed: () => [],
81-
disallowed: () => [],
82-
},
77+
allowed = () => [],
78+
disallowed = () => [],
79+
}: { allowed?: () => (HTMLElement | null)[]; disallowed?: () => (HTMLElement | null)[] } = {},
8380
enabled = true
8481
) {
8582
useIsoMorphicEffect(() => {
@@ -88,39 +85,35 @@ export function useInertOthers(
8885
let d = disposables()
8986

9087
// Mark all disallowed elements as inert
91-
if (disallowed) {
92-
for (let element of disallowed()) {
93-
if (!element) continue
88+
for (let element of disallowed()) {
89+
if (!element) continue
9490

95-
d.add(markInert(element))
96-
}
91+
d.add(markInert(element))
9792
}
9893

9994
// Mark all siblings of allowed elements (and parents) as inert
100-
if (allowed) {
101-
let allowedElements = allowed()
102-
103-
for (let element of allowedElements) {
104-
if (!element) continue
95+
let allowedElements = allowed()
10596

106-
let ownerDocument = getOwnerDocument(element)
107-
if (!ownerDocument) continue
97+
for (let element of allowedElements) {
98+
if (!element) continue
10899

109-
let parent = element.parentElement
110-
while (parent && parent !== ownerDocument.body) {
111-
// Mark all siblings as inert
112-
for (let node of parent.childNodes) {
113-
// If the node contains any of the elements we should not mark it as inert
114-
// because it would make the elements unreachable.
115-
if (allowedElements.some((el) => node.contains(el))) continue
100+
let ownerDocument = getOwnerDocument(element)
101+
if (!ownerDocument) continue
116102

117-
// Mark the node as inert
118-
d.add(markInert(node as HTMLElement))
119-
}
103+
let parent = element.parentElement
104+
while (parent && parent !== ownerDocument.body) {
105+
// Mark all siblings as inert
106+
for (let node of parent.childNodes) {
107+
// If the node contains any of the elements we should not mark it as inert
108+
// because it would make the elements unreachable.
109+
if (allowedElements.some((el) => node.contains(el))) continue
120110

121-
// Move up the tree
122-
parent = parent.parentElement
111+
// Mark the node as inert
112+
d.add(markInert(node as HTMLElement))
123113
}
114+
115+
// Move up the tree
116+
parent = parent.parentElement
124117
}
125118
}
126119

0 commit comments

Comments
 (0)