Skip to content

Commit be50125

Browse files
authored
Un-revert "fix(#4313): ariaHideOutside/aria-modal-polyfill: use inert instead of aria-hidden where supported (#4314) #4881 (#4883)
* Revert "Revert "fix(#4313): ariaHideOutside/aria-modal-polyfill: use inert instead of aria-hidden where supported (#4314)" (#4881)" This reverts commit 8e6cefd. * useLayoutEffect -> useEffect in usePopover
1 parent 1775ff2 commit be50125

File tree

4 files changed

+20
-13
lines changed

4 files changed

+20
-13
lines changed

packages/@react-aria/aria-modal-polyfill/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212

13-
import {hideOthers} from 'aria-hidden';
13+
import {suppressOthers} from 'aria-hidden';
1414

1515
type Revert = () => void;
1616

@@ -49,7 +49,7 @@ export function watchModals(selector:string = 'body', {document = currentDocumen
4949
let modal = addNode.querySelector('[aria-modal="true"], [data-ismodal="true"]') as HTMLElement;
5050
undo?.();
5151
let others = [modal, ... liveAnnouncer ? [liveAnnouncer as HTMLElement] : []];
52-
undo = hideOthers(others);
52+
undo = suppressOthers(others);
5353
}
5454
} else if (mutation.type === 'childList' && mutation.removedNodes.length > 0) {
5555
let removedNodes = Array.from(mutation.removedNodes);
@@ -60,7 +60,7 @@ export function watchModals(selector:string = 'body', {document = currentDocumen
6060
if (modalContainers.length > 0) {
6161
let modal = modalContainers[modalContainers.length - 1].querySelector('[aria-modal="true"], [data-ismodal="true"]') as HTMLElement;
6262
let others = [modal, ... liveAnnouncer ? [liveAnnouncer as HTMLElement] : []];
63-
undo = hideOthers(others);
63+
undo = suppressOthers(others);
6464
} else {
6565
undo = undefined;
6666
}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
let refCountMap = new WeakMap<Element, number>();
1616
let observerStack = [];
1717

18+
const supportsInert = typeof HTMLElement !== 'undefined' && Object.prototype.hasOwnProperty.call(HTMLElement.prototype, 'inert');
19+
1820
/**
1921
* Hides all elements in the DOM outside the given targets from screen readers using aria-hidden,
2022
* and returns a function to revert these changes. In addition, changes to the DOM are watched
@@ -81,11 +83,14 @@ export function ariaHideOutside(targets: Element[], root = document.body) {
8183

8284
// If already aria-hidden, and the ref count is zero, then this element
8385
// was already hidden and there's nothing for us to do.
84-
if (node.getAttribute('aria-hidden') === 'true' && refCount === 0) {
86+
let alreadyHidden = supportsInert && node instanceof HTMLElement ? node.inert : node.getAttribute('aria-hidden') === 'true';
87+
if (alreadyHidden && refCount === 0) {
8588
return;
8689
}
8790

8891
if (refCount === 0) {
92+
supportsInert && node instanceof HTMLElement ?
93+
node.inert = true :
8994
node.setAttribute('aria-hidden', 'true');
9095
}
9196

@@ -150,6 +155,8 @@ export function ariaHideOutside(targets: Element[], root = document.body) {
150155
for (let node of hiddenNodes) {
151156
let count = refCountMap.get(node);
152157
if (count === 1) {
158+
supportsInert && node instanceof HTMLElement ?
159+
node.inert = false :
153160
node.removeAttribute('aria-hidden');
154161
refCountMap.delete(node);
155162
} else {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
import {ariaHideOutside} from './ariaHideOutside';
1414
import {AriaPositionProps, useOverlayPosition} from './useOverlayPosition';
1515
import {DOMAttributes} from '@react-types/shared';
16-
import {mergeProps, useLayoutEffect} from '@react-aria/utils';
16+
import {mergeProps} from '@react-aria/utils';
1717
import {OverlayTriggerState} from '@react-stately/overlays';
1818
import {PlacementAxis} from '@react-types/overlays';
19-
import {RefObject} from 'react';
19+
import {RefObject, useEffect} from 'react';
2020
import {useOverlay} from './useOverlay';
2121
import {usePreventScroll} from './usePreventScroll';
2222

@@ -96,7 +96,7 @@ export function usePopover(props: AriaPopoverProps, state: OverlayTriggerState):
9696
isDisabled: isNonModal
9797
});
9898

99-
useLayoutEffect(() => {
99+
useEffect(() => {
100100
if (state.isOpen && !isNonModal && popoverRef.current) {
101101
return ariaHideOutside([popoverRef.current]);
102102
}

yarn.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5831,12 +5831,12 @@ argparse@^2.0.1:
58315831
resolved "https://registry.yarnpkg.com/argparse/-/argparse-2.0.1.tgz#246f50f3ca78a3240f6c997e8a9bd1eac49e4b38"
58325832
integrity sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==
58335833

5834-
aria-hidden@^1.1.1:
5835-
version "1.1.1"
5836-
resolved "https://registry.yarnpkg.com/aria-hidden/-/aria-hidden-1.1.1.tgz#0c356026d3f65e2bd487a3adb73f0c586be2c37e"
5837-
integrity sha512-M7zYxCcOQPOaxGHoMTKUFD2UNcVFTp9ycrdStLcTPLf8zgTXC3+YcGe+UuzSh5X1BX/0/PtS8xTNy4xyH/6xtw==
5834+
aria-hidden@^1.2.3:
5835+
version "1.2.3"
5836+
resolved "https://registry.yarnpkg.com/aria-hidden/-/aria-hidden-1.2.3.tgz#14aeb7fb692bbb72d69bebfa47279c1fd725e954"
5837+
integrity sha512-xcLxITLe2HYa1cnYnwCjkOO1PqUHQpozB8x9AR0OgWN2woOBi5kSDVxKfd0b7sb1hw5qFeJhXm9H1nu3xSfLeQ==
58385838
dependencies:
5839-
tslib "^1.0.0"
5839+
tslib "^2.0.0"
58405840

58415841
aria-query@^5.0.0:
58425842
version "5.0.0"
@@ -21894,7 +21894,7 @@ tslib@2.4.0, tslib@^2.0.0, tslib@^2.0.1, tslib@^2.1.0, tslib@^2.4.0:
2189421894
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.4.0.tgz#7cecaa7f073ce680a05847aa77be941098f36dc3"
2189521895
integrity sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==
2189621896

21897-
tslib@^1.0.0, tslib@^1.10.0, tslib@^1.8.1, tslib@^1.9.0:
21897+
tslib@^1.10.0, tslib@^1.8.1, tslib@^1.9.0:
2189821898
version "1.13.0"
2189921899
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.13.0.tgz#c881e13cc7015894ed914862d276436fa9a47043"
2190021900
integrity sha512-i/6DQjL8Xf3be4K/E6Wgpekn5Qasl1usyw++dAA35Ue5orEn65VIxOA+YvNNl9HV3qv70T7CNwjODHZrLwvd1Q==

0 commit comments

Comments
 (0)