@@ -17,10 +17,6 @@ let observerStack = [];
17
17
18
18
const supportsInert = typeof HTMLElement !== 'undefined' && Object . prototype . hasOwnProperty . call ( HTMLElement . prototype , 'inert' ) ;
19
19
20
- interface InertElement extends HTMLElement {
21
- inert : boolean
22
- }
23
-
24
20
/**
25
21
* Hides all elements in the DOM outside the given targets from screen readers using aria-hidden,
26
22
* and returns a function to revert these changes. In addition, changes to the DOM are watched
@@ -87,14 +83,14 @@ export function ariaHideOutside(targets: Element[], root = document.body) {
87
83
88
84
// If already aria-hidden, and the ref count is zero, then this element
89
85
// was already hidden and there's nothing for us to do.
90
- let alreadyHidden = supportsInert ? ( node as InertElement ) . inert : node . getAttribute ( 'aria-hidden' ) === 'true' ;
86
+ let alreadyHidden = supportsInert && node instanceof HTMLElement ? node . inert : node . getAttribute ( 'aria-hidden' ) === 'true' ;
91
87
if ( alreadyHidden && refCount === 0 ) {
92
88
return ;
93
89
}
94
90
95
91
if ( refCount === 0 ) {
96
- supportsInert ?
97
- ( ( node as InertElement ) . inert = true ) :
92
+ supportsInert && node instanceof HTMLElement ?
93
+ node . inert = true :
98
94
node . setAttribute ( 'aria-hidden' , 'true' ) ;
99
95
}
100
96
@@ -159,8 +155,8 @@ export function ariaHideOutside(targets: Element[], root = document.body) {
159
155
for ( let node of hiddenNodes ) {
160
156
let count = refCountMap . get ( node ) ;
161
157
if ( count === 1 ) {
162
- supportsInert ?
163
- ( ( node as InertElement ) . inert = false ) :
158
+ supportsInert && node instanceof HTMLElement ?
159
+ node . inert = false :
164
160
node . removeAttribute ( 'aria-hidden' ) ;
165
161
refCountMap . delete ( node ) ;
166
162
} else {
0 commit comments