@react-aria/focus 3.16.1 → 3.17.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 (46) hide show
  1. package/dist/FocusRing.main.js +44 -0
  2. package/dist/FocusRing.main.js.map +1 -0
  3. package/dist/FocusRing.mjs +35 -0
  4. package/dist/FocusRing.module.js +35 -0
  5. package/dist/FocusRing.module.js.map +1 -0
  6. package/dist/FocusScope.main.js +728 -0
  7. package/dist/FocusScope.main.js.map +1 -0
  8. package/dist/FocusScope.mjs +714 -0
  9. package/dist/FocusScope.module.js +714 -0
  10. package/dist/FocusScope.module.js.map +1 -0
  11. package/dist/focusSafely.main.js +39 -0
  12. package/dist/focusSafely.main.js.map +1 -0
  13. package/dist/focusSafely.mjs +34 -0
  14. package/dist/focusSafely.module.js +34 -0
  15. package/dist/focusSafely.module.js.map +1 -0
  16. package/dist/import.mjs +7 -939
  17. package/dist/isElementVisible.main.js +41 -0
  18. package/dist/isElementVisible.main.js.map +1 -0
  19. package/dist/isElementVisible.mjs +36 -0
  20. package/dist/isElementVisible.module.js +36 -0
  21. package/dist/isElementVisible.module.js.map +1 -0
  22. package/dist/main.js +18 -953
  23. package/dist/main.js.map +1 -1
  24. package/dist/module.js +7 -939
  25. package/dist/module.js.map +1 -1
  26. package/dist/types.d.ts +1 -0
  27. package/dist/types.d.ts.map +1 -1
  28. package/dist/useFocusRing.main.js +50 -0
  29. package/dist/useFocusRing.main.js.map +1 -0
  30. package/dist/useFocusRing.mjs +45 -0
  31. package/dist/useFocusRing.module.js +45 -0
  32. package/dist/useFocusRing.module.js.map +1 -0
  33. package/dist/useFocusable.main.js +75 -0
  34. package/dist/useFocusable.main.js.map +1 -0
  35. package/dist/useFocusable.mjs +65 -0
  36. package/dist/useFocusable.module.js +65 -0
  37. package/dist/useFocusable.module.js.map +1 -0
  38. package/dist/useHasTabbableChild.main.js +62 -0
  39. package/dist/useHasTabbableChild.main.js.map +1 -0
  40. package/dist/useHasTabbableChild.mjs +57 -0
  41. package/dist/useHasTabbableChild.module.js +57 -0
  42. package/dist/useHasTabbableChild.module.js.map +1 -0
  43. package/package.json +5 -5
  44. package/src/FocusScope.tsx +6 -2
  45. package/src/index.ts +1 -1
  46. package/src/isElementVisible.ts +2 -0
@@ -0,0 +1,62 @@
1
+ var $a7a032acae3ddda9$exports = require("./FocusScope.main.js");
2
+ var $6RLDH$react = require("react");
3
+ var $6RLDH$reactariautils = require("@react-aria/utils");
4
+
5
+
6
+ function $parcel$export(e, n, v, s) {
7
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
8
+ }
9
+
10
+ $parcel$export(module.exports, "useHasTabbableChild", () => $259c6413a286f2e6$export$eac1895992b9f3d6);
11
+ /*
12
+ * Copyright 2022 Adobe. All rights reserved.
13
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
14
+ * you may not use this file except in compliance with the License. You may obtain a copy
15
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software distributed under
18
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
19
+ * OF ANY KIND, either express or implied. See the License for the specific language
20
+ * governing permissions and limitations under the License.
21
+ */
22
+
23
+
24
+ function $259c6413a286f2e6$export$eac1895992b9f3d6(ref, options) {
25
+ let isDisabled = options === null || options === void 0 ? void 0 : options.isDisabled;
26
+ let [hasTabbableChild, setHasTabbableChild] = (0, $6RLDH$react.useState)(false);
27
+ (0, $6RLDH$reactariautils.useLayoutEffect)(()=>{
28
+ if ((ref === null || ref === void 0 ? void 0 : ref.current) && !isDisabled) {
29
+ let update = ()=>{
30
+ if (ref.current) {
31
+ let walker = (0, $a7a032acae3ddda9$exports.getFocusableTreeWalker)(ref.current, {
32
+ tabbable: true
33
+ });
34
+ setHasTabbableChild(!!walker.nextNode());
35
+ }
36
+ };
37
+ update();
38
+ // Update when new elements are inserted, or the tabIndex/disabled attribute updates.
39
+ let observer = new MutationObserver(update);
40
+ observer.observe(ref.current, {
41
+ subtree: true,
42
+ childList: true,
43
+ attributes: true,
44
+ attributeFilter: [
45
+ "tabIndex",
46
+ "disabled"
47
+ ]
48
+ });
49
+ return ()=>{
50
+ // Disconnect mutation observer when a React update occurs on the top-level component
51
+ // so we update synchronously after re-rendering. Otherwise React will emit act warnings
52
+ // in tests since mutation observers fire asynchronously. The mutation observer is necessary
53
+ // so we also update if a child component re-renders and adds/removes something tabbable.
54
+ observer.disconnect();
55
+ };
56
+ }
57
+ });
58
+ return isDisabled ? false : hasTabbableChild;
59
+ }
60
+
61
+
62
+ //# sourceMappingURL=useHasTabbableChild.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;AAmBM,SAAS,0CAAoB,GAAuB,EAAE,OAAqC;IAChG,IAAI,aAAa,oBAAA,8BAAA,QAAS,UAAU;IACpC,IAAI,CAAC,kBAAkB,oBAAoB,GAAG,CAAA,GAAA,qBAAO,EAAE;IAEvD,CAAA,GAAA,qCAAc,EAAE;QACd,IAAI,CAAA,gBAAA,0BAAA,IAAK,OAAO,KAAI,CAAC,YAAY;YAC/B,IAAI,SAAS;gBACX,IAAI,IAAI,OAAO,EAAE;oBACf,IAAI,SAAS,CAAA,GAAA,gDAAqB,EAAE,IAAI,OAAO,EAAE;wBAAC,UAAU;oBAAI;oBAChE,oBAAoB,CAAC,CAAC,OAAO,QAAQ;gBACvC;YACF;YAEA;YAEA,qFAAqF;YACrF,IAAI,WAAW,IAAI,iBAAiB;YACpC,SAAS,OAAO,CAAC,IAAI,OAAO,EAAE;gBAC5B,SAAS;gBACT,WAAW;gBACX,YAAY;gBACZ,iBAAiB;oBAAC;oBAAY;iBAAW;YAC3C;YAEA,OAAO;gBACL,qFAAqF;gBACrF,wFAAwF;gBACxF,4FAA4F;gBAC5F,yFAAyF;gBACzF,SAAS,UAAU;YACrB;QACF;IACF;IAEA,OAAO,aAAa,QAAQ;AAC9B","sources":["packages/@react-aria/focus/src/useHasTabbableChild.ts"],"sourcesContent":["/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {getFocusableTreeWalker} from './FocusScope';\nimport {RefObject, useState} from 'react';\nimport {useLayoutEffect} from '@react-aria/utils';\n\ninterface AriaHasTabbableChildOptions {\n isDisabled?: boolean\n}\n\n// This was created for a special empty case of a component that can have child or\n// be empty, like Collection/Virtualizer/Table/ListView/etc. When these components\n// are empty they can have a message with a tabbable element, which is like them\n// being not empty, when it comes to focus and tab order.\n\n/**\n * Returns whether an element has a tabbable child, and updates as children change.\n * @private\n */\nexport function useHasTabbableChild(ref: RefObject<Element>, options?: AriaHasTabbableChildOptions): boolean {\n let isDisabled = options?.isDisabled;\n let [hasTabbableChild, setHasTabbableChild] = useState(false);\n\n useLayoutEffect(() => {\n if (ref?.current && !isDisabled) {\n let update = () => {\n if (ref.current) {\n let walker = getFocusableTreeWalker(ref.current, {tabbable: true});\n setHasTabbableChild(!!walker.nextNode());\n }\n };\n\n update();\n\n // Update when new elements are inserted, or the tabIndex/disabled attribute updates.\n let observer = new MutationObserver(update);\n observer.observe(ref.current, {\n subtree: true,\n childList: true,\n attributes: true,\n attributeFilter: ['tabIndex', 'disabled']\n });\n\n return () => {\n // Disconnect mutation observer when a React update occurs on the top-level component\n // so we update synchronously after re-rendering. Otherwise React will emit act warnings\n // in tests since mutation observers fire asynchronously. The mutation observer is necessary\n // so we also update if a child component re-renders and adds/removes something tabbable.\n observer.disconnect();\n };\n }\n });\n\n return isDisabled ? false : hasTabbableChild;\n}\n"],"names":[],"version":3,"file":"useHasTabbableChild.main.js.map"}
@@ -0,0 +1,57 @@
1
+ import {getFocusableTreeWalker as $9bf71ea28793e738$export$2d6ec8fc375ceafa} from "./FocusScope.mjs";
2
+ import {useState as $hGAaG$useState} from "react";
3
+ import {useLayoutEffect as $hGAaG$useLayoutEffect} from "@react-aria/utils";
4
+
5
+ /*
6
+ * Copyright 2022 Adobe. All rights reserved.
7
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License. You may obtain a copy
9
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software distributed under
12
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
13
+ * OF ANY KIND, either express or implied. See the License for the specific language
14
+ * governing permissions and limitations under the License.
15
+ */
16
+
17
+
18
+ function $83013635b024ae3d$export$eac1895992b9f3d6(ref, options) {
19
+ let isDisabled = options === null || options === void 0 ? void 0 : options.isDisabled;
20
+ let [hasTabbableChild, setHasTabbableChild] = (0, $hGAaG$useState)(false);
21
+ (0, $hGAaG$useLayoutEffect)(()=>{
22
+ if ((ref === null || ref === void 0 ? void 0 : ref.current) && !isDisabled) {
23
+ let update = ()=>{
24
+ if (ref.current) {
25
+ let walker = (0, $9bf71ea28793e738$export$2d6ec8fc375ceafa)(ref.current, {
26
+ tabbable: true
27
+ });
28
+ setHasTabbableChild(!!walker.nextNode());
29
+ }
30
+ };
31
+ update();
32
+ // Update when new elements are inserted, or the tabIndex/disabled attribute updates.
33
+ let observer = new MutationObserver(update);
34
+ observer.observe(ref.current, {
35
+ subtree: true,
36
+ childList: true,
37
+ attributes: true,
38
+ attributeFilter: [
39
+ "tabIndex",
40
+ "disabled"
41
+ ]
42
+ });
43
+ return ()=>{
44
+ // Disconnect mutation observer when a React update occurs on the top-level component
45
+ // so we update synchronously after re-rendering. Otherwise React will emit act warnings
46
+ // in tests since mutation observers fire asynchronously. The mutation observer is necessary
47
+ // so we also update if a child component re-renders and adds/removes something tabbable.
48
+ observer.disconnect();
49
+ };
50
+ }
51
+ });
52
+ return isDisabled ? false : hasTabbableChild;
53
+ }
54
+
55
+
56
+ export {$83013635b024ae3d$export$eac1895992b9f3d6 as useHasTabbableChild};
57
+ //# sourceMappingURL=useHasTabbableChild.mjs.map
@@ -0,0 +1,57 @@
1
+ import {getFocusableTreeWalker as $9bf71ea28793e738$export$2d6ec8fc375ceafa} from "./FocusScope.module.js";
2
+ import {useState as $hGAaG$useState} from "react";
3
+ import {useLayoutEffect as $hGAaG$useLayoutEffect} from "@react-aria/utils";
4
+
5
+ /*
6
+ * Copyright 2022 Adobe. All rights reserved.
7
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License. You may obtain a copy
9
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software distributed under
12
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
13
+ * OF ANY KIND, either express or implied. See the License for the specific language
14
+ * governing permissions and limitations under the License.
15
+ */
16
+
17
+
18
+ function $83013635b024ae3d$export$eac1895992b9f3d6(ref, options) {
19
+ let isDisabled = options === null || options === void 0 ? void 0 : options.isDisabled;
20
+ let [hasTabbableChild, setHasTabbableChild] = (0, $hGAaG$useState)(false);
21
+ (0, $hGAaG$useLayoutEffect)(()=>{
22
+ if ((ref === null || ref === void 0 ? void 0 : ref.current) && !isDisabled) {
23
+ let update = ()=>{
24
+ if (ref.current) {
25
+ let walker = (0, $9bf71ea28793e738$export$2d6ec8fc375ceafa)(ref.current, {
26
+ tabbable: true
27
+ });
28
+ setHasTabbableChild(!!walker.nextNode());
29
+ }
30
+ };
31
+ update();
32
+ // Update when new elements are inserted, or the tabIndex/disabled attribute updates.
33
+ let observer = new MutationObserver(update);
34
+ observer.observe(ref.current, {
35
+ subtree: true,
36
+ childList: true,
37
+ attributes: true,
38
+ attributeFilter: [
39
+ "tabIndex",
40
+ "disabled"
41
+ ]
42
+ });
43
+ return ()=>{
44
+ // Disconnect mutation observer when a React update occurs on the top-level component
45
+ // so we update synchronously after re-rendering. Otherwise React will emit act warnings
46
+ // in tests since mutation observers fire asynchronously. The mutation observer is necessary
47
+ // so we also update if a child component re-renders and adds/removes something tabbable.
48
+ observer.disconnect();
49
+ };
50
+ }
51
+ });
52
+ return isDisabled ? false : hasTabbableChild;
53
+ }
54
+
55
+
56
+ export {$83013635b024ae3d$export$eac1895992b9f3d6 as useHasTabbableChild};
57
+ //# sourceMappingURL=useHasTabbableChild.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;AAAA;;;;;;;;;;CAUC;;;AAmBM,SAAS,0CAAoB,GAAuB,EAAE,OAAqC;IAChG,IAAI,aAAa,oBAAA,8BAAA,QAAS,UAAU;IACpC,IAAI,CAAC,kBAAkB,oBAAoB,GAAG,CAAA,GAAA,eAAO,EAAE;IAEvD,CAAA,GAAA,sBAAc,EAAE;QACd,IAAI,CAAA,gBAAA,0BAAA,IAAK,OAAO,KAAI,CAAC,YAAY;YAC/B,IAAI,SAAS;gBACX,IAAI,IAAI,OAAO,EAAE;oBACf,IAAI,SAAS,CAAA,GAAA,yCAAqB,EAAE,IAAI,OAAO,EAAE;wBAAC,UAAU;oBAAI;oBAChE,oBAAoB,CAAC,CAAC,OAAO,QAAQ;gBACvC;YACF;YAEA;YAEA,qFAAqF;YACrF,IAAI,WAAW,IAAI,iBAAiB;YACpC,SAAS,OAAO,CAAC,IAAI,OAAO,EAAE;gBAC5B,SAAS;gBACT,WAAW;gBACX,YAAY;gBACZ,iBAAiB;oBAAC;oBAAY;iBAAW;YAC3C;YAEA,OAAO;gBACL,qFAAqF;gBACrF,wFAAwF;gBACxF,4FAA4F;gBAC5F,yFAAyF;gBACzF,SAAS,UAAU;YACrB;QACF;IACF;IAEA,OAAO,aAAa,QAAQ;AAC9B","sources":["packages/@react-aria/focus/src/useHasTabbableChild.ts"],"sourcesContent":["/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {getFocusableTreeWalker} from './FocusScope';\nimport {RefObject, useState} from 'react';\nimport {useLayoutEffect} from '@react-aria/utils';\n\ninterface AriaHasTabbableChildOptions {\n isDisabled?: boolean\n}\n\n// This was created for a special empty case of a component that can have child or\n// be empty, like Collection/Virtualizer/Table/ListView/etc. When these components\n// are empty they can have a message with a tabbable element, which is like them\n// being not empty, when it comes to focus and tab order.\n\n/**\n * Returns whether an element has a tabbable child, and updates as children change.\n * @private\n */\nexport function useHasTabbableChild(ref: RefObject<Element>, options?: AriaHasTabbableChildOptions): boolean {\n let isDisabled = options?.isDisabled;\n let [hasTabbableChild, setHasTabbableChild] = useState(false);\n\n useLayoutEffect(() => {\n if (ref?.current && !isDisabled) {\n let update = () => {\n if (ref.current) {\n let walker = getFocusableTreeWalker(ref.current, {tabbable: true});\n setHasTabbableChild(!!walker.nextNode());\n }\n };\n\n update();\n\n // Update when new elements are inserted, or the tabIndex/disabled attribute updates.\n let observer = new MutationObserver(update);\n observer.observe(ref.current, {\n subtree: true,\n childList: true,\n attributes: true,\n attributeFilter: ['tabIndex', 'disabled']\n });\n\n return () => {\n // Disconnect mutation observer when a React update occurs on the top-level component\n // so we update synchronously after re-rendering. Otherwise React will emit act warnings\n // in tests since mutation observers fire asynchronously. The mutation observer is necessary\n // so we also update if a child component re-renders and adds/removes something tabbable.\n observer.disconnect();\n };\n }\n });\n\n return isDisabled ? false : hasTabbableChild;\n}\n"],"names":[],"version":3,"file":"useHasTabbableChild.module.js.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-aria/focus",
3
- "version": "3.16.1",
3
+ "version": "3.17.0",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -22,9 +22,9 @@
22
22
  "url": "https://github.com/adobe/react-spectrum"
23
23
  },
24
24
  "dependencies": {
25
- "@react-aria/interactions": "^3.21.0",
26
- "@react-aria/utils": "^3.23.1",
27
- "@react-types/shared": "^3.22.0",
25
+ "@react-aria/interactions": "^3.21.2",
26
+ "@react-aria/utils": "^3.24.0",
27
+ "@react-types/shared": "^3.23.0",
28
28
  "@swc/helpers": "^0.5.0",
29
29
  "clsx": "^2.0.0"
30
30
  },
@@ -34,5 +34,5 @@
34
34
  "publishConfig": {
35
35
  "access": "public"
36
36
  },
37
- "gitHead": "f040ff62678e6a31375b96c05396df0bae660350"
37
+ "gitHead": "f645f29edc1322153fd60af4640cbcab1d992dbd"
38
38
  }
@@ -278,6 +278,10 @@ const FOCUSABLE_ELEMENT_SELECTOR = focusableElements.join(':not([hidden]),') + '
278
278
  focusableElements.push('[tabindex]:not([tabindex="-1"]):not([disabled])');
279
279
  const TABBABLE_ELEMENT_SELECTOR = focusableElements.join(':not([hidden]):not([tabindex="-1"]),');
280
280
 
281
+ export function isFocusable(element: HTMLElement) {
282
+ return element.matches(FOCUSABLE_ELEMENT_SELECTOR);
283
+ }
284
+
281
285
  function getScopeRoot(scope: Element[]) {
282
286
  return scope[0].parentElement!;
283
287
  }
@@ -314,7 +318,7 @@ function useFocusContainment(scopeRef: RefObject<Element[]>, contain?: boolean)
314
318
 
315
319
  // Handle the Tab key to contain focus within the scope
316
320
  let onKeyDown = (e) => {
317
- if (e.key !== 'Tab' || e.altKey || e.ctrlKey || e.metaKey || !shouldContainFocus(scopeRef)) {
321
+ if (e.key !== 'Tab' || e.altKey || e.ctrlKey || e.metaKey || !shouldContainFocus(scopeRef) || e.isComposing) {
318
322
  return;
319
323
  }
320
324
 
@@ -585,7 +589,7 @@ function useRestoreFocus(scopeRef: RefObject<Element[]>, restoreFocus?: boolean,
585
589
  // using portals for overlays, so that focus goes to the expected element when
586
590
  // tabbing out of the overlay.
587
591
  let onKeyDown = (e: KeyboardEvent) => {
588
- if (e.key !== 'Tab' || e.altKey || e.ctrlKey || e.metaKey || !shouldContainFocus(scopeRef)) {
592
+ if (e.key !== 'Tab' || e.altKey || e.ctrlKey || e.metaKey || !shouldContainFocus(scopeRef) || e.isComposing) {
589
593
  return;
590
594
  }
591
595
 
package/src/index.ts CHANGED
@@ -10,7 +10,7 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
- export {FocusScope, useFocusManager, getFocusableTreeWalker, createFocusManager, isElementInChildOfActiveScope} from './FocusScope';
13
+ export {FocusScope, useFocusManager, getFocusableTreeWalker, createFocusManager, isElementInChildOfActiveScope, isFocusable} from './FocusScope';
14
14
  export {FocusRing} from './FocusRing';
15
15
  export {FocusableProvider, useFocusable} from './useFocusable';
16
16
  export {useFocusRing} from './useFocusRing';
@@ -43,6 +43,8 @@ function isStyleVisible(element: Element) {
43
43
  function isAttributeVisible(element: Element, childElement?: Element) {
44
44
  return (
45
45
  !element.hasAttribute('hidden') &&
46
+ // Ignore HiddenSelect when tree walking.
47
+ !element.hasAttribute('data-react-aria-prevent-focus') &&
46
48
  (element.nodeName === 'DETAILS' &&
47
49
  childElement &&
48
50
  childElement.nodeName !== 'SUMMARY'