Skip to content

Commit e5ffb75

Browse files
authored
Properly apply aria-hidden on non HTMLElements (#4868)
svgs were still accessible by screenreaders durning DnD operations, this fixes that
1 parent e5582ce commit e5ffb75

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

packages/@react-aria/overlays/src/ariaHideOutside.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ let observerStack = [];
1717

1818
const supportsInert = typeof HTMLElement !== 'undefined' && Object.prototype.hasOwnProperty.call(HTMLElement.prototype, 'inert');
1919

20-
interface InertElement extends HTMLElement {
21-
inert: boolean
22-
}
23-
2420
/**
2521
* Hides all elements in the DOM outside the given targets from screen readers using aria-hidden,
2622
* 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) {
8783

8884
// If already aria-hidden, and the ref count is zero, then this element
8985
// 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';
9187
if (alreadyHidden && refCount === 0) {
9288
return;
9389
}
9490

9591
if (refCount === 0) {
96-
supportsInert ?
97-
((node as InertElement).inert = true) :
92+
supportsInert && node instanceof HTMLElement ?
93+
node.inert = true :
9894
node.setAttribute('aria-hidden', 'true');
9995
}
10096

@@ -159,8 +155,8 @@ export function ariaHideOutside(targets: Element[], root = document.body) {
159155
for (let node of hiddenNodes) {
160156
let count = refCountMap.get(node);
161157
if (count === 1) {
162-
supportsInert ?
163-
((node as InertElement).inert = false) :
158+
supportsInert && node instanceof HTMLElement ?
159+
node.inert = false :
164160
node.removeAttribute('aria-hidden');
165161
refCountMap.delete(node);
166162
} else {

0 commit comments

Comments
 (0)