@react-aria/overlays 3.31.1 → 3.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (263) hide show
  1. package/dist/import.mjs +12 -12
  2. package/dist/main.js +28 -28
  3. package/dist/main.js.map +1 -1
  4. package/dist/module.js +12 -12
  5. package/dist/module.js.map +1 -1
  6. package/dist/types/src/index.d.ts +19 -0
  7. package/package.json +15 -21
  8. package/src/index.ts +19 -22
  9. package/dist/DismissButton.main.js +0 -51
  10. package/dist/DismissButton.main.js.map +0 -1
  11. package/dist/DismissButton.mjs +0 -46
  12. package/dist/DismissButton.module.js +0 -46
  13. package/dist/DismissButton.module.js.map +0 -1
  14. package/dist/Overlay.main.js +0 -73
  15. package/dist/Overlay.main.js.map +0 -1
  16. package/dist/Overlay.mjs +0 -63
  17. package/dist/Overlay.module.js +0 -63
  18. package/dist/Overlay.module.js.map +0 -1
  19. package/dist/PortalProvider.main.js +0 -41
  20. package/dist/PortalProvider.main.js.map +0 -1
  21. package/dist/PortalProvider.mjs +0 -31
  22. package/dist/PortalProvider.module.js +0 -31
  23. package/dist/PortalProvider.module.js.map +0 -1
  24. package/dist/ar-AE.main.js +0 -6
  25. package/dist/ar-AE.main.js.map +0 -1
  26. package/dist/ar-AE.mjs +0 -8
  27. package/dist/ar-AE.module.js +0 -8
  28. package/dist/ar-AE.module.js.map +0 -1
  29. package/dist/ariaHideOutside.main.js +0 -152
  30. package/dist/ariaHideOutside.main.js.map +0 -1
  31. package/dist/ariaHideOutside.mjs +0 -146
  32. package/dist/ariaHideOutside.module.js +0 -146
  33. package/dist/ariaHideOutside.module.js.map +0 -1
  34. package/dist/bg-BG.main.js +0 -6
  35. package/dist/bg-BG.main.js.map +0 -1
  36. package/dist/bg-BG.mjs +0 -8
  37. package/dist/bg-BG.module.js +0 -8
  38. package/dist/bg-BG.module.js.map +0 -1
  39. package/dist/calculatePosition.main.js +0 -414
  40. package/dist/calculatePosition.main.js.map +0 -1
  41. package/dist/calculatePosition.mjs +0 -408
  42. package/dist/calculatePosition.module.js +0 -408
  43. package/dist/calculatePosition.module.js.map +0 -1
  44. package/dist/cs-CZ.main.js +0 -6
  45. package/dist/cs-CZ.main.js.map +0 -1
  46. package/dist/cs-CZ.mjs +0 -8
  47. package/dist/cs-CZ.module.js +0 -8
  48. package/dist/cs-CZ.module.js.map +0 -1
  49. package/dist/da-DK.main.js +0 -6
  50. package/dist/da-DK.main.js.map +0 -1
  51. package/dist/da-DK.mjs +0 -8
  52. package/dist/da-DK.module.js +0 -8
  53. package/dist/da-DK.module.js.map +0 -1
  54. package/dist/de-DE.main.js +0 -6
  55. package/dist/de-DE.main.js.map +0 -1
  56. package/dist/de-DE.mjs +0 -8
  57. package/dist/de-DE.module.js +0 -8
  58. package/dist/de-DE.module.js.map +0 -1
  59. package/dist/el-GR.main.js +0 -6
  60. package/dist/el-GR.main.js.map +0 -1
  61. package/dist/el-GR.mjs +0 -8
  62. package/dist/el-GR.module.js +0 -8
  63. package/dist/el-GR.module.js.map +0 -1
  64. package/dist/en-US.main.js +0 -6
  65. package/dist/en-US.main.js.map +0 -1
  66. package/dist/en-US.mjs +0 -8
  67. package/dist/en-US.module.js +0 -8
  68. package/dist/en-US.module.js.map +0 -1
  69. package/dist/es-ES.main.js +0 -6
  70. package/dist/es-ES.main.js.map +0 -1
  71. package/dist/es-ES.mjs +0 -8
  72. package/dist/es-ES.module.js +0 -8
  73. package/dist/es-ES.module.js.map +0 -1
  74. package/dist/et-EE.main.js +0 -6
  75. package/dist/et-EE.main.js.map +0 -1
  76. package/dist/et-EE.mjs +0 -8
  77. package/dist/et-EE.module.js +0 -8
  78. package/dist/et-EE.module.js.map +0 -1
  79. package/dist/fi-FI.main.js +0 -6
  80. package/dist/fi-FI.main.js.map +0 -1
  81. package/dist/fi-FI.mjs +0 -8
  82. package/dist/fi-FI.module.js +0 -8
  83. package/dist/fi-FI.module.js.map +0 -1
  84. package/dist/fr-FR.main.js +0 -6
  85. package/dist/fr-FR.main.js.map +0 -1
  86. package/dist/fr-FR.mjs +0 -8
  87. package/dist/fr-FR.module.js +0 -8
  88. package/dist/fr-FR.module.js.map +0 -1
  89. package/dist/he-IL.main.js +0 -6
  90. package/dist/he-IL.main.js.map +0 -1
  91. package/dist/he-IL.mjs +0 -8
  92. package/dist/he-IL.module.js +0 -8
  93. package/dist/he-IL.module.js.map +0 -1
  94. package/dist/hr-HR.main.js +0 -6
  95. package/dist/hr-HR.main.js.map +0 -1
  96. package/dist/hr-HR.mjs +0 -8
  97. package/dist/hr-HR.module.js +0 -8
  98. package/dist/hr-HR.module.js.map +0 -1
  99. package/dist/hu-HU.main.js +0 -6
  100. package/dist/hu-HU.main.js.map +0 -1
  101. package/dist/hu-HU.mjs +0 -8
  102. package/dist/hu-HU.module.js +0 -8
  103. package/dist/hu-HU.module.js.map +0 -1
  104. package/dist/intlStrings.main.js +0 -108
  105. package/dist/intlStrings.main.js.map +0 -1
  106. package/dist/intlStrings.mjs +0 -110
  107. package/dist/intlStrings.module.js +0 -110
  108. package/dist/intlStrings.module.js.map +0 -1
  109. package/dist/it-IT.main.js +0 -6
  110. package/dist/it-IT.main.js.map +0 -1
  111. package/dist/it-IT.mjs +0 -8
  112. package/dist/it-IT.module.js +0 -8
  113. package/dist/it-IT.module.js.map +0 -1
  114. package/dist/ja-JP.main.js +0 -6
  115. package/dist/ja-JP.main.js.map +0 -1
  116. package/dist/ja-JP.mjs +0 -8
  117. package/dist/ja-JP.module.js +0 -8
  118. package/dist/ja-JP.module.js.map +0 -1
  119. package/dist/ko-KR.main.js +0 -6
  120. package/dist/ko-KR.main.js.map +0 -1
  121. package/dist/ko-KR.mjs +0 -8
  122. package/dist/ko-KR.module.js +0 -8
  123. package/dist/ko-KR.module.js.map +0 -1
  124. package/dist/lt-LT.main.js +0 -6
  125. package/dist/lt-LT.main.js.map +0 -1
  126. package/dist/lt-LT.mjs +0 -8
  127. package/dist/lt-LT.module.js +0 -8
  128. package/dist/lt-LT.module.js.map +0 -1
  129. package/dist/lv-LV.main.js +0 -6
  130. package/dist/lv-LV.main.js.map +0 -1
  131. package/dist/lv-LV.mjs +0 -8
  132. package/dist/lv-LV.module.js +0 -8
  133. package/dist/lv-LV.module.js.map +0 -1
  134. package/dist/nb-NO.main.js +0 -6
  135. package/dist/nb-NO.main.js.map +0 -1
  136. package/dist/nb-NO.mjs +0 -8
  137. package/dist/nb-NO.module.js +0 -8
  138. package/dist/nb-NO.module.js.map +0 -1
  139. package/dist/nl-NL.main.js +0 -6
  140. package/dist/nl-NL.main.js.map +0 -1
  141. package/dist/nl-NL.mjs +0 -8
  142. package/dist/nl-NL.module.js +0 -8
  143. package/dist/nl-NL.module.js.map +0 -1
  144. package/dist/pl-PL.main.js +0 -6
  145. package/dist/pl-PL.main.js.map +0 -1
  146. package/dist/pl-PL.mjs +0 -8
  147. package/dist/pl-PL.module.js +0 -8
  148. package/dist/pl-PL.module.js.map +0 -1
  149. package/dist/pt-BR.main.js +0 -6
  150. package/dist/pt-BR.main.js.map +0 -1
  151. package/dist/pt-BR.mjs +0 -8
  152. package/dist/pt-BR.module.js +0 -8
  153. package/dist/pt-BR.module.js.map +0 -1
  154. package/dist/pt-PT.main.js +0 -6
  155. package/dist/pt-PT.main.js.map +0 -1
  156. package/dist/pt-PT.mjs +0 -8
  157. package/dist/pt-PT.module.js +0 -8
  158. package/dist/pt-PT.module.js.map +0 -1
  159. package/dist/ro-RO.main.js +0 -6
  160. package/dist/ro-RO.main.js.map +0 -1
  161. package/dist/ro-RO.mjs +0 -8
  162. package/dist/ro-RO.module.js +0 -8
  163. package/dist/ro-RO.module.js.map +0 -1
  164. package/dist/ru-RU.main.js +0 -6
  165. package/dist/ru-RU.main.js.map +0 -1
  166. package/dist/ru-RU.mjs +0 -8
  167. package/dist/ru-RU.module.js +0 -8
  168. package/dist/ru-RU.module.js.map +0 -1
  169. package/dist/sk-SK.main.js +0 -6
  170. package/dist/sk-SK.main.js.map +0 -1
  171. package/dist/sk-SK.mjs +0 -8
  172. package/dist/sk-SK.module.js +0 -8
  173. package/dist/sk-SK.module.js.map +0 -1
  174. package/dist/sl-SI.main.js +0 -6
  175. package/dist/sl-SI.main.js.map +0 -1
  176. package/dist/sl-SI.mjs +0 -8
  177. package/dist/sl-SI.module.js +0 -8
  178. package/dist/sl-SI.module.js.map +0 -1
  179. package/dist/sr-SP.main.js +0 -6
  180. package/dist/sr-SP.main.js.map +0 -1
  181. package/dist/sr-SP.mjs +0 -8
  182. package/dist/sr-SP.module.js +0 -8
  183. package/dist/sr-SP.module.js.map +0 -1
  184. package/dist/sv-SE.main.js +0 -6
  185. package/dist/sv-SE.main.js.map +0 -1
  186. package/dist/sv-SE.mjs +0 -8
  187. package/dist/sv-SE.module.js +0 -8
  188. package/dist/sv-SE.module.js.map +0 -1
  189. package/dist/tr-TR.main.js +0 -6
  190. package/dist/tr-TR.main.js.map +0 -1
  191. package/dist/tr-TR.mjs +0 -8
  192. package/dist/tr-TR.module.js +0 -8
  193. package/dist/tr-TR.module.js.map +0 -1
  194. package/dist/types.d.ts +0 -355
  195. package/dist/types.d.ts.map +0 -1
  196. package/dist/uk-UA.main.js +0 -6
  197. package/dist/uk-UA.main.js.map +0 -1
  198. package/dist/uk-UA.mjs +0 -8
  199. package/dist/uk-UA.module.js +0 -8
  200. package/dist/uk-UA.module.js.map +0 -1
  201. package/dist/useCloseOnScroll.main.js +0 -52
  202. package/dist/useCloseOnScroll.main.js.map +0 -1
  203. package/dist/useCloseOnScroll.mjs +0 -46
  204. package/dist/useCloseOnScroll.module.js +0 -46
  205. package/dist/useCloseOnScroll.module.js.map +0 -1
  206. package/dist/useModal.main.js +0 -118
  207. package/dist/useModal.main.js.map +0 -1
  208. package/dist/useModal.mjs +0 -105
  209. package/dist/useModal.module.js +0 -105
  210. package/dist/useModal.module.js.map +0 -1
  211. package/dist/useModalOverlay.main.js +0 -57
  212. package/dist/useModalOverlay.main.js.map +0 -1
  213. package/dist/useModalOverlay.mjs +0 -52
  214. package/dist/useModalOverlay.module.js +0 -52
  215. package/dist/useModalOverlay.module.js.map +0 -1
  216. package/dist/useOverlay.main.js +0 -111
  217. package/dist/useOverlay.main.js.map +0 -1
  218. package/dist/useOverlay.mjs +0 -106
  219. package/dist/useOverlay.module.js +0 -106
  220. package/dist/useOverlay.module.js.map +0 -1
  221. package/dist/useOverlayPosition.main.js +0 -225
  222. package/dist/useOverlayPosition.main.js.map +0 -1
  223. package/dist/useOverlayPosition.mjs +0 -220
  224. package/dist/useOverlayPosition.module.js +0 -220
  225. package/dist/useOverlayPosition.module.js.map +0 -1
  226. package/dist/useOverlayTrigger.main.js +0 -54
  227. package/dist/useOverlayTrigger.main.js.map +0 -1
  228. package/dist/useOverlayTrigger.mjs +0 -49
  229. package/dist/useOverlayTrigger.module.js +0 -49
  230. package/dist/useOverlayTrigger.module.js.map +0 -1
  231. package/dist/usePopover.main.js +0 -77
  232. package/dist/usePopover.main.js.map +0 -1
  233. package/dist/usePopover.mjs +0 -72
  234. package/dist/usePopover.module.js +0 -72
  235. package/dist/usePopover.module.js.map +0 -1
  236. package/dist/usePreventScroll.main.js +0 -215
  237. package/dist/usePreventScroll.main.js.map +0 -1
  238. package/dist/usePreventScroll.mjs +0 -210
  239. package/dist/usePreventScroll.module.js +0 -210
  240. package/dist/usePreventScroll.module.js.map +0 -1
  241. package/dist/zh-CN.main.js +0 -6
  242. package/dist/zh-CN.main.js.map +0 -1
  243. package/dist/zh-CN.mjs +0 -8
  244. package/dist/zh-CN.module.js +0 -8
  245. package/dist/zh-CN.module.js.map +0 -1
  246. package/dist/zh-TW.main.js +0 -6
  247. package/dist/zh-TW.main.js.map +0 -1
  248. package/dist/zh-TW.mjs +0 -8
  249. package/dist/zh-TW.module.js +0 -8
  250. package/dist/zh-TW.module.js.map +0 -1
  251. package/src/DismissButton.tsx +0 -52
  252. package/src/Overlay.tsx +0 -95
  253. package/src/PortalProvider.tsx +0 -41
  254. package/src/ariaHideOutside.ts +0 -221
  255. package/src/calculatePosition.ts +0 -680
  256. package/src/useCloseOnScroll.ts +0 -65
  257. package/src/useModal.tsx +0 -197
  258. package/src/useModalOverlay.ts +0 -69
  259. package/src/useOverlay.ts +0 -169
  260. package/src/useOverlayPosition.ts +0 -327
  261. package/src/useOverlayTrigger.ts +0 -72
  262. package/src/usePopover.ts +0 -138
  263. package/src/usePreventScroll.ts +0 -273
package/src/Overlay.tsx DELETED
@@ -1,95 +0,0 @@
1
- /*
2
- * Copyright 2022 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */
12
-
13
- import {ClearPressResponder} from '@react-aria/interactions';
14
- import {FocusScope} from '@react-aria/focus';
15
- import React, {ReactNode, useContext, useMemo, useState} from 'react';
16
- import ReactDOM from 'react-dom';
17
- import {useIsSSR} from '@react-aria/ssr';
18
- import {useLayoutEffect} from '@react-aria/utils';
19
- import {useUNSAFE_PortalContext} from './PortalProvider';
20
-
21
- export interface OverlayProps {
22
- /**
23
- * The container element in which the overlay portal will be placed.
24
- * @default document.body
25
- */
26
- portalContainer?: Element,
27
- /** The overlay to render in the portal. */
28
- children: ReactNode,
29
- /**
30
- * Disables default focus management for the overlay, including containment and restoration.
31
- * This option should be used very carefully. When focus management is disabled, you must
32
- * implement focus containment and restoration to ensure the overlay is keyboard accessible.
33
- */
34
- disableFocusManagement?: boolean,
35
- /**
36
- * Whether to contain focus within the overlay.
37
- */
38
- shouldContainFocus?: boolean,
39
- /**
40
- * Whether the overlay is currently performing an exit animation. When true,
41
- * focus is allowed to move outside.
42
- */
43
- isExiting?: boolean
44
- }
45
-
46
- export const OverlayContext: React.Context<{contain: boolean, setContain: React.Dispatch<React.SetStateAction<boolean>>} | null> =
47
- React.createContext<{contain: boolean, setContain: React.Dispatch<React.SetStateAction<boolean>>} | null>(null);
48
-
49
- /**
50
- * A container which renders an overlay such as a popover or modal in a portal,
51
- * and provides a focus scope for the child elements.
52
- */
53
- export function Overlay(props: OverlayProps): React.ReactPortal | null {
54
- let isSSR = useIsSSR();
55
- let {portalContainer = isSSR ? null : document.body, isExiting} = props;
56
- let [contain, setContain] = useState(false);
57
- let contextValue = useMemo(() => ({contain, setContain}), [contain, setContain]);
58
-
59
- let {getContainer} = useUNSAFE_PortalContext();
60
- if (!props.portalContainer && getContainer) {
61
- portalContainer = getContainer();
62
- }
63
-
64
- if (!portalContainer) {
65
- return null;
66
- }
67
-
68
- let contents = props.children;
69
- if (!props.disableFocusManagement) {
70
- contents = (
71
- <FocusScope restoreFocus contain={(props.shouldContainFocus || contain) && !isExiting}>
72
- {contents}
73
- </FocusScope>
74
- );
75
- }
76
-
77
- contents = (
78
- <OverlayContext.Provider value={contextValue}>
79
- <ClearPressResponder>
80
- {contents}
81
- </ClearPressResponder>
82
- </OverlayContext.Provider>
83
- );
84
-
85
- return ReactDOM.createPortal(contents, portalContainer);
86
- }
87
-
88
- /** @private */
89
- export function useOverlayFocusContain(): void {
90
- let ctx = useContext(OverlayContext);
91
- let setContain = ctx?.setContain;
92
- useLayoutEffect(() => {
93
- setContain?.(true);
94
- }, [setContain]);
95
- }
@@ -1,41 +0,0 @@
1
- /*
2
- * Copyright 2024 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */
12
-
13
- import React, {createContext, JSX, ReactNode, useContext} from 'react';
14
-
15
- export interface PortalProviderProps {
16
- /** Should return the element where we should portal to. Can clear the context by passing null. */
17
- getContainer?: (() => HTMLElement | null) | null,
18
- /** The content of the PortalProvider. Should contain all children that want to portal their overlays to the element returned by the provided `getContainer()`. */
19
- children: ReactNode
20
- }
21
-
22
- export interface PortalProviderContextValue extends Omit<PortalProviderProps, 'children'>{};
23
-
24
- export const PortalContext: React.Context<PortalProviderContextValue> = createContext<PortalProviderContextValue>({});
25
-
26
- /**
27
- * Sets the portal container for all overlay elements rendered by its children.
28
- */
29
- export function UNSAFE_PortalProvider(props: PortalProviderProps): JSX.Element {
30
- let {getContainer} = props;
31
- let {getContainer: ctxGetContainer} = useUNSAFE_PortalContext();
32
- return (
33
- <PortalContext.Provider value={{getContainer: getContainer === null ? undefined : getContainer ?? ctxGetContainer}}>
34
- {props.children}
35
- </PortalContext.Provider>
36
- );
37
- }
38
-
39
- export function useUNSAFE_PortalContext(): PortalProviderContextValue {
40
- return useContext(PortalContext) ?? {};
41
- }
@@ -1,221 +0,0 @@
1
- /*
2
- * Copyright 2020 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */
12
-
13
- import {getOwnerWindow, nodeContains} from '@react-aria/utils';
14
- const supportsInert = typeof HTMLElement !== 'undefined' && 'inert' in HTMLElement.prototype;
15
-
16
- interface AriaHideOutsideOptions {
17
- root?: Element,
18
- shouldUseInert?: boolean
19
- }
20
-
21
- // Keeps a ref count of all hidden elements. Added to when hiding an element, and
22
- // subtracted from when showing it again. When it reaches zero, aria-hidden is removed.
23
- let refCountMap = new WeakMap<Element, number>();
24
- interface ObserverWrapper {
25
- visibleNodes: Set<Element>,
26
- hiddenNodes: Set<Element>,
27
- observe: () => void,
28
- disconnect: () => void
29
- }
30
- let observerStack: Array<ObserverWrapper> = [];
31
-
32
- /**
33
- * Hides all elements in the DOM outside the given targets from screen readers using aria-hidden,
34
- * and returns a function to revert these changes. In addition, changes to the DOM are watched
35
- * and new elements outside the targets are automatically hidden.
36
- * @param targets - The elements that should remain visible.
37
- * @param root - Nothing will be hidden above this element.
38
- * @returns - A function to restore all hidden elements.
39
- */
40
- export function ariaHideOutside(targets: Element[], options?: AriaHideOutsideOptions | Element) {
41
- let windowObj = getOwnerWindow(targets?.[0]);
42
- let opts = options instanceof windowObj.Element ? {root: options} : options;
43
- let root = opts?.root ?? document.body;
44
- let shouldUseInert = opts?.shouldUseInert && supportsInert;
45
- let visibleNodes = new Set<Element>(targets);
46
- let hiddenNodes = new Set<Element>();
47
-
48
- let getHidden = (element: Element) => {
49
- return shouldUseInert && element instanceof windowObj.HTMLElement ? element.inert : element.getAttribute('aria-hidden') === 'true';
50
- };
51
-
52
- let setHidden = (element: Element, hidden: boolean) => {
53
- if (shouldUseInert && element instanceof windowObj.HTMLElement) {
54
- element.inert = hidden;
55
- } else if (hidden) {
56
- element.setAttribute('aria-hidden', 'true');
57
- } else {
58
- element.removeAttribute('aria-hidden');
59
- if (element instanceof windowObj.HTMLElement) {
60
- // We only ever call setHidden with hidden = false when the nodeCount is 1 aka
61
- // we are trying to make the element visible to screen readers again, so remove inert as well
62
- element.inert = false;
63
- }
64
- }
65
- };
66
-
67
- let walk = (root: Element) => {
68
- // Keep live announcer and top layer elements (e.g. toasts) visible.
69
- for (let element of root.querySelectorAll('[data-live-announcer], [data-react-aria-top-layer]')) {
70
- visibleNodes.add(element);
71
- }
72
-
73
- let acceptNode = (node: Element) => {
74
- // Skip this node and its children if it is one of the target nodes, or a live announcer.
75
- // Also skip children of already hidden nodes, as aria-hidden is recursive. An exception is
76
- // made for elements with role="row" since VoiceOver on iOS has issues hiding elements with role="row".
77
- // For that case we want to hide the cells inside as well (https://bugs.webkit.org/show_bug.cgi?id=222623).
78
- if (
79
- hiddenNodes.has(node) ||
80
- visibleNodes.has(node) ||
81
- (node.parentElement && hiddenNodes.has(node.parentElement) && node.parentElement.getAttribute('role') !== 'row')
82
- ) {
83
- return NodeFilter.FILTER_REJECT;
84
- }
85
-
86
- // Skip this node but continue to children if one of the targets is inside the node.
87
- for (let target of visibleNodes) {
88
- if (nodeContains(node, target)) {
89
- return NodeFilter.FILTER_SKIP;
90
- }
91
- }
92
-
93
- return NodeFilter.FILTER_ACCEPT;
94
- };
95
-
96
- let walker = document.createTreeWalker(
97
- root,
98
- NodeFilter.SHOW_ELEMENT,
99
- {acceptNode}
100
- );
101
-
102
- // TreeWalker does not include the root.
103
- let acceptRoot = acceptNode(root);
104
- if (acceptRoot === NodeFilter.FILTER_ACCEPT) {
105
- hide(root);
106
- }
107
-
108
- if (acceptRoot !== NodeFilter.FILTER_REJECT) {
109
- let node = walker.nextNode() as Element;
110
- while (node != null) {
111
- hide(node);
112
- node = walker.nextNode() as Element;
113
- }
114
- }
115
- };
116
-
117
- let hide = (node: Element) => {
118
- let refCount = refCountMap.get(node) ?? 0;
119
-
120
- // If already aria-hidden, and the ref count is zero, then this element
121
- // was already hidden and there's nothing for us to do.
122
- if (getHidden(node) && refCount === 0) {
123
- return;
124
- }
125
-
126
- if (refCount === 0) {
127
- setHidden(node, true);
128
- }
129
-
130
- hiddenNodes.add(node);
131
- refCountMap.set(node, refCount + 1);
132
- };
133
-
134
- // If there is already a MutationObserver listening from a previous call,
135
- // disconnect it so the new on takes over.
136
- if (observerStack.length) {
137
- observerStack[observerStack.length - 1].disconnect();
138
- }
139
-
140
- walk(root);
141
-
142
- let observer = new MutationObserver(changes => {
143
- for (let change of changes) {
144
- if (change.type !== 'childList') {
145
- continue;
146
- }
147
-
148
- // If the parent element of the added nodes is not within one of the targets,
149
- // and not already inside a hidden node, hide all of the new children.
150
- if (
151
- change.target.isConnected &&
152
- ![...visibleNodes, ...hiddenNodes].some((node) =>
153
- nodeContains(node, change.target)
154
- )
155
- ) {
156
- for (let node of change.addedNodes) {
157
- if (
158
- (node instanceof HTMLElement || node instanceof SVGElement) &&
159
- (node.dataset.liveAnnouncer === 'true' || node.dataset.reactAriaTopLayer === 'true')
160
- ) {
161
- visibleNodes.add(node);
162
- } else if (node instanceof Element) {
163
- walk(node);
164
- }
165
- }
166
- }
167
- }
168
- });
169
-
170
- observer.observe(root, {childList: true, subtree: true});
171
-
172
- let observerWrapper: ObserverWrapper = {
173
- visibleNodes,
174
- hiddenNodes,
175
- observe() {
176
- observer.observe(root, {childList: true, subtree: true});
177
- },
178
- disconnect() {
179
- observer.disconnect();
180
- }
181
- };
182
-
183
- observerStack.push(observerWrapper);
184
-
185
- return (): void => {
186
- observer.disconnect();
187
-
188
- for (let node of hiddenNodes) {
189
- let count = refCountMap.get(node);
190
- if (count == null) {
191
- continue;
192
- }
193
- if (count === 1) {
194
- setHidden(node, false);
195
- refCountMap.delete(node);
196
- } else {
197
- refCountMap.set(node, count - 1);
198
- }
199
- }
200
-
201
- // Remove this observer from the stack, and start the previous one.
202
- if (observerWrapper === observerStack[observerStack.length - 1]) {
203
- observerStack.pop();
204
- if (observerStack.length) {
205
- observerStack[observerStack.length - 1].observe();
206
- }
207
- } else {
208
- observerStack.splice(observerStack.indexOf(observerWrapper), 1);
209
- }
210
- };
211
- }
212
-
213
- export function keepVisible(element: Element): (() => void) | undefined {
214
- let observer = observerStack[observerStack.length - 1];
215
- if (observer && !observer.visibleNodes.has(element)) {
216
- observer.visibleNodes.add(element);
217
- return () => {
218
- observer.visibleNodes.delete(element);
219
- };
220
- }
221
- }