@@ -74,12 +74,9 @@ function markNotInert(element: HTMLElement) {
74
74
*/
75
75
export function useInertOthers (
76
76
{
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 ) [ ] } = { } ,
83
80
enabled = true
84
81
) {
85
82
useIsoMorphicEffect ( ( ) => {
@@ -88,39 +85,35 @@ export function useInertOthers(
88
85
let d = disposables ( )
89
86
90
87
// 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
94
90
95
- d . add ( markInert ( element ) )
96
- }
91
+ d . add ( markInert ( element ) )
97
92
}
98
93
99
94
// 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 ( )
105
96
106
- let ownerDocument = getOwnerDocument ( element )
107
- if ( ! ownerDocument ) continue
97
+ for ( let element of allowedElements ) {
98
+ if ( ! element ) continue
108
99
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
116
102
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
120
110
121
- // Move up the tree
122
- parent = parent . parentElement
111
+ // Mark the node as inert
112
+ d . add ( markInert ( node as HTMLElement ) )
123
113
}
114
+
115
+ // Move up the tree
116
+ parent = parent . parentElement
124
117
}
125
118
}
126
119
0 commit comments