@react-aria/focus 3.21.5 → 3.22.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.
- package/dist/import.mjs +16 -8
- package/dist/main.js +32 -24
- package/dist/main.js.map +1 -1
- package/dist/module.js +16 -8
- package/dist/module.js.map +1 -1
- package/dist/types/src/index.d.ts +16 -0
- package/package.json +14 -14
- package/src/index.ts +16 -13
- package/dist/FocusRing.main.js +0 -44
- package/dist/FocusRing.main.js.map +0 -1
- package/dist/FocusRing.mjs +0 -35
- package/dist/FocusRing.module.js +0 -35
- package/dist/FocusRing.module.js.map +0 -1
- package/dist/FocusScope.main.js +0 -760
- package/dist/FocusScope.main.js.map +0 -1
- package/dist/FocusScope.mjs +0 -747
- package/dist/FocusScope.module.js +0 -747
- package/dist/FocusScope.module.js.map +0 -1
- package/dist/types.d.ts +0 -133
- package/dist/types.d.ts.map +0 -1
- package/dist/useFocusRing.main.js +0 -55
- package/dist/useFocusRing.main.js.map +0 -1
- package/dist/useFocusRing.mjs +0 -50
- package/dist/useFocusRing.module.js +0 -50
- package/dist/useFocusRing.module.js.map +0 -1
- package/dist/useHasTabbableChild.main.js +0 -62
- package/dist/useHasTabbableChild.main.js.map +0 -1
- package/dist/useHasTabbableChild.mjs +0 -57
- package/dist/useHasTabbableChild.module.js +0 -57
- package/dist/useHasTabbableChild.module.js.map +0 -1
- package/dist/virtualFocus.main.js +0 -46
- package/dist/virtualFocus.main.js.map +0 -1
- package/dist/virtualFocus.mjs +0 -38
- package/dist/virtualFocus.module.js +0 -38
- package/dist/virtualFocus.module.js.map +0 -1
- package/src/FocusRing.tsx +0 -55
- package/src/FocusScope.tsx +0 -1039
- package/src/useFocusRing.ts +0 -79
- package/src/useHasTabbableChild.ts +0 -66
- package/src/virtualFocus.ts +0 -33
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import {getFocusableTreeWalker as $9bf71ea28793e738$export$2d6ec8fc375ceafa} from "./FocusScope.module.js";
|
|
2
|
-
import {useLayoutEffect as $hGAaG$useLayoutEffect} from "@react-aria/utils";
|
|
3
|
-
import {useState as $hGAaG$useState} from "react";
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":";;;;AAAA;;;;;;;;;;CAUC;;;AAoBM,SAAS,0CAAoB,GAA8B,EAAE,OAAqC;IACvG,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} from '@react-types/shared';\nimport {useLayoutEffect} from '@react-aria/utils';\nimport {useState} from 'react';\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 | null>, 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"}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
var $jMsK8$reactariautils = require("@react-aria/utils");
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
function $parcel$export(e, n, v, s) {
|
|
5
|
-
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
$parcel$export(module.exports, "moveVirtualFocus", () => $a756eb2d3b28d089$export$76e4e37e5339496d);
|
|
9
|
-
$parcel$export(module.exports, "getVirtuallyFocusedElement", () => $a756eb2d3b28d089$export$759df0d867455a91);
|
|
10
|
-
$parcel$export(module.exports, "dispatchVirtualBlur", () => $a756eb2d3b28d089$export$6c5dc7e81d2cc29a);
|
|
11
|
-
$parcel$export(module.exports, "dispatchVirtualFocus", () => $a756eb2d3b28d089$export$2b35b76d2e30e129);
|
|
12
|
-
|
|
13
|
-
function $a756eb2d3b28d089$export$76e4e37e5339496d(to) {
|
|
14
|
-
let from = $a756eb2d3b28d089$export$759df0d867455a91((0, $jMsK8$reactariautils.getOwnerDocument)(to));
|
|
15
|
-
if (from !== to) {
|
|
16
|
-
if (from) $a756eb2d3b28d089$export$6c5dc7e81d2cc29a(from, to);
|
|
17
|
-
if (to) $a756eb2d3b28d089$export$2b35b76d2e30e129(to, from);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
function $a756eb2d3b28d089$export$6c5dc7e81d2cc29a(from, to) {
|
|
21
|
-
from.dispatchEvent(new FocusEvent('blur', {
|
|
22
|
-
relatedTarget: to
|
|
23
|
-
}));
|
|
24
|
-
from.dispatchEvent(new FocusEvent('focusout', {
|
|
25
|
-
bubbles: true,
|
|
26
|
-
relatedTarget: to
|
|
27
|
-
}));
|
|
28
|
-
}
|
|
29
|
-
function $a756eb2d3b28d089$export$2b35b76d2e30e129(to, from) {
|
|
30
|
-
to.dispatchEvent(new FocusEvent('focus', {
|
|
31
|
-
relatedTarget: from
|
|
32
|
-
}));
|
|
33
|
-
to.dispatchEvent(new FocusEvent('focusin', {
|
|
34
|
-
bubbles: true,
|
|
35
|
-
relatedTarget: from
|
|
36
|
-
}));
|
|
37
|
-
}
|
|
38
|
-
function $a756eb2d3b28d089$export$759df0d867455a91(document) {
|
|
39
|
-
let activeElement = (0, $jMsK8$reactariautils.getActiveElement)(document);
|
|
40
|
-
let activeDescendant = activeElement === null || activeElement === void 0 ? void 0 : activeElement.getAttribute('aria-activedescendant');
|
|
41
|
-
if (activeDescendant) return document.getElementById(activeDescendant) || activeElement;
|
|
42
|
-
return activeElement;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
//# sourceMappingURL=virtualFocus.main.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;AAEO,SAAS,0CAAiB,EAAkB;IACjD,IAAI,OAAO,0CAA2B,CAAA,GAAA,sCAAe,EAAE;IACvD,IAAI,SAAS,IAAI;QACf,IAAI,MACF,0CAAoB,MAAM;QAE5B,IAAI,IACF,0CAAqB,IAAI;IAE7B;AACF;AAEO,SAAS,0CAAoB,IAAa,EAAE,EAAkB;IACnE,KAAK,aAAa,CAAC,IAAI,WAAW,QAAQ;QAAC,eAAe;IAAE;IAC5D,KAAK,aAAa,CAAC,IAAI,WAAW,YAAY;QAAC,SAAS;QAAM,eAAe;IAAE;AACjF;AAEO,SAAS,0CAAqB,EAAW,EAAE,IAAoB;IACpE,GAAG,aAAa,CAAC,IAAI,WAAW,SAAS;QAAC,eAAe;IAAI;IAC7D,GAAG,aAAa,CAAC,IAAI,WAAW,WAAW;QAAC,SAAS;QAAM,eAAe;IAAI;AAChF;AAEO,SAAS,0CAA2B,QAAkB;IAC3D,IAAI,gBAAgB,CAAA,GAAA,sCAAe,EAAE;IACrC,IAAI,mBAAmB,0BAAA,oCAAA,cAAe,YAAY,CAAC;IACnD,IAAI,kBACF,OAAO,SAAS,cAAc,CAAC,qBAAqB;IAGtD,OAAO;AACT","sources":["packages/@react-aria/focus/src/virtualFocus.ts"],"sourcesContent":["import {getActiveElement, getOwnerDocument} from '@react-aria/utils';\n\nexport function moveVirtualFocus(to: Element | null): void {\n let from = getVirtuallyFocusedElement(getOwnerDocument(to));\n if (from !== to) {\n if (from) {\n dispatchVirtualBlur(from, to);\n }\n if (to) {\n dispatchVirtualFocus(to, from);\n }\n }\n}\n\nexport function dispatchVirtualBlur(from: Element, to: Element | null): void {\n from.dispatchEvent(new FocusEvent('blur', {relatedTarget: to}));\n from.dispatchEvent(new FocusEvent('focusout', {bubbles: true, relatedTarget: to}));\n}\n\nexport function dispatchVirtualFocus(to: Element, from: Element | null): void {\n to.dispatchEvent(new FocusEvent('focus', {relatedTarget: from}));\n to.dispatchEvent(new FocusEvent('focusin', {bubbles: true, relatedTarget: from}));\n}\n\nexport function getVirtuallyFocusedElement(document: Document): Element | null {\n let activeElement = getActiveElement(document);\n let activeDescendant = activeElement?.getAttribute('aria-activedescendant');\n if (activeDescendant) {\n return document.getElementById(activeDescendant) || activeElement;\n }\n\n return activeElement;\n}\n"],"names":[],"version":3,"file":"virtualFocus.main.js.map"}
|
package/dist/virtualFocus.mjs
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import {getOwnerDocument as $hpDQO$getOwnerDocument, getActiveElement as $hpDQO$getActiveElement} from "@react-aria/utils";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
function $55f9b1ae81f22853$export$76e4e37e5339496d(to) {
|
|
5
|
-
let from = $55f9b1ae81f22853$export$759df0d867455a91((0, $hpDQO$getOwnerDocument)(to));
|
|
6
|
-
if (from !== to) {
|
|
7
|
-
if (from) $55f9b1ae81f22853$export$6c5dc7e81d2cc29a(from, to);
|
|
8
|
-
if (to) $55f9b1ae81f22853$export$2b35b76d2e30e129(to, from);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
function $55f9b1ae81f22853$export$6c5dc7e81d2cc29a(from, to) {
|
|
12
|
-
from.dispatchEvent(new FocusEvent('blur', {
|
|
13
|
-
relatedTarget: to
|
|
14
|
-
}));
|
|
15
|
-
from.dispatchEvent(new FocusEvent('focusout', {
|
|
16
|
-
bubbles: true,
|
|
17
|
-
relatedTarget: to
|
|
18
|
-
}));
|
|
19
|
-
}
|
|
20
|
-
function $55f9b1ae81f22853$export$2b35b76d2e30e129(to, from) {
|
|
21
|
-
to.dispatchEvent(new FocusEvent('focus', {
|
|
22
|
-
relatedTarget: from
|
|
23
|
-
}));
|
|
24
|
-
to.dispatchEvent(new FocusEvent('focusin', {
|
|
25
|
-
bubbles: true,
|
|
26
|
-
relatedTarget: from
|
|
27
|
-
}));
|
|
28
|
-
}
|
|
29
|
-
function $55f9b1ae81f22853$export$759df0d867455a91(document) {
|
|
30
|
-
let activeElement = (0, $hpDQO$getActiveElement)(document);
|
|
31
|
-
let activeDescendant = activeElement === null || activeElement === void 0 ? void 0 : activeElement.getAttribute('aria-activedescendant');
|
|
32
|
-
if (activeDescendant) return document.getElementById(activeDescendant) || activeElement;
|
|
33
|
-
return activeElement;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
export {$55f9b1ae81f22853$export$76e4e37e5339496d as moveVirtualFocus, $55f9b1ae81f22853$export$759df0d867455a91 as getVirtuallyFocusedElement, $55f9b1ae81f22853$export$6c5dc7e81d2cc29a as dispatchVirtualBlur, $55f9b1ae81f22853$export$2b35b76d2e30e129 as dispatchVirtualFocus};
|
|
38
|
-
//# sourceMappingURL=virtualFocus.module.js.map
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import {getOwnerDocument as $hpDQO$getOwnerDocument, getActiveElement as $hpDQO$getActiveElement} from "@react-aria/utils";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
function $55f9b1ae81f22853$export$76e4e37e5339496d(to) {
|
|
5
|
-
let from = $55f9b1ae81f22853$export$759df0d867455a91((0, $hpDQO$getOwnerDocument)(to));
|
|
6
|
-
if (from !== to) {
|
|
7
|
-
if (from) $55f9b1ae81f22853$export$6c5dc7e81d2cc29a(from, to);
|
|
8
|
-
if (to) $55f9b1ae81f22853$export$2b35b76d2e30e129(to, from);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
function $55f9b1ae81f22853$export$6c5dc7e81d2cc29a(from, to) {
|
|
12
|
-
from.dispatchEvent(new FocusEvent('blur', {
|
|
13
|
-
relatedTarget: to
|
|
14
|
-
}));
|
|
15
|
-
from.dispatchEvent(new FocusEvent('focusout', {
|
|
16
|
-
bubbles: true,
|
|
17
|
-
relatedTarget: to
|
|
18
|
-
}));
|
|
19
|
-
}
|
|
20
|
-
function $55f9b1ae81f22853$export$2b35b76d2e30e129(to, from) {
|
|
21
|
-
to.dispatchEvent(new FocusEvent('focus', {
|
|
22
|
-
relatedTarget: from
|
|
23
|
-
}));
|
|
24
|
-
to.dispatchEvent(new FocusEvent('focusin', {
|
|
25
|
-
bubbles: true,
|
|
26
|
-
relatedTarget: from
|
|
27
|
-
}));
|
|
28
|
-
}
|
|
29
|
-
function $55f9b1ae81f22853$export$759df0d867455a91(document) {
|
|
30
|
-
let activeElement = (0, $hpDQO$getActiveElement)(document);
|
|
31
|
-
let activeDescendant = activeElement === null || activeElement === void 0 ? void 0 : activeElement.getAttribute('aria-activedescendant');
|
|
32
|
-
if (activeDescendant) return document.getElementById(activeDescendant) || activeElement;
|
|
33
|
-
return activeElement;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
export {$55f9b1ae81f22853$export$76e4e37e5339496d as moveVirtualFocus, $55f9b1ae81f22853$export$759df0d867455a91 as getVirtuallyFocusedElement, $55f9b1ae81f22853$export$6c5dc7e81d2cc29a as dispatchVirtualBlur, $55f9b1ae81f22853$export$2b35b76d2e30e129 as dispatchVirtualFocus};
|
|
38
|
-
//# sourceMappingURL=virtualFocus.module.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":";;;AAEO,SAAS,0CAAiB,EAAkB;IACjD,IAAI,OAAO,0CAA2B,CAAA,GAAA,uBAAe,EAAE;IACvD,IAAI,SAAS,IAAI;QACf,IAAI,MACF,0CAAoB,MAAM;QAE5B,IAAI,IACF,0CAAqB,IAAI;IAE7B;AACF;AAEO,SAAS,0CAAoB,IAAa,EAAE,EAAkB;IACnE,KAAK,aAAa,CAAC,IAAI,WAAW,QAAQ;QAAC,eAAe;IAAE;IAC5D,KAAK,aAAa,CAAC,IAAI,WAAW,YAAY;QAAC,SAAS;QAAM,eAAe;IAAE;AACjF;AAEO,SAAS,0CAAqB,EAAW,EAAE,IAAoB;IACpE,GAAG,aAAa,CAAC,IAAI,WAAW,SAAS;QAAC,eAAe;IAAI;IAC7D,GAAG,aAAa,CAAC,IAAI,WAAW,WAAW;QAAC,SAAS;QAAM,eAAe;IAAI;AAChF;AAEO,SAAS,0CAA2B,QAAkB;IAC3D,IAAI,gBAAgB,CAAA,GAAA,uBAAe,EAAE;IACrC,IAAI,mBAAmB,0BAAA,oCAAA,cAAe,YAAY,CAAC;IACnD,IAAI,kBACF,OAAO,SAAS,cAAc,CAAC,qBAAqB;IAGtD,OAAO;AACT","sources":["packages/@react-aria/focus/src/virtualFocus.ts"],"sourcesContent":["import {getActiveElement, getOwnerDocument} from '@react-aria/utils';\n\nexport function moveVirtualFocus(to: Element | null): void {\n let from = getVirtuallyFocusedElement(getOwnerDocument(to));\n if (from !== to) {\n if (from) {\n dispatchVirtualBlur(from, to);\n }\n if (to) {\n dispatchVirtualFocus(to, from);\n }\n }\n}\n\nexport function dispatchVirtualBlur(from: Element, to: Element | null): void {\n from.dispatchEvent(new FocusEvent('blur', {relatedTarget: to}));\n from.dispatchEvent(new FocusEvent('focusout', {bubbles: true, relatedTarget: to}));\n}\n\nexport function dispatchVirtualFocus(to: Element, from: Element | null): void {\n to.dispatchEvent(new FocusEvent('focus', {relatedTarget: from}));\n to.dispatchEvent(new FocusEvent('focusin', {bubbles: true, relatedTarget: from}));\n}\n\nexport function getVirtuallyFocusedElement(document: Document): Element | null {\n let activeElement = getActiveElement(document);\n let activeDescendant = activeElement?.getAttribute('aria-activedescendant');\n if (activeDescendant) {\n return document.getElementById(activeDescendant) || activeElement;\n }\n\n return activeElement;\n}\n"],"names":[],"version":3,"file":"virtualFocus.module.js.map"}
|
package/src/FocusRing.tsx
DELETED
|
@@ -1,55 +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 clsx from 'clsx';
|
|
14
|
-
import {mergeProps} from '@react-aria/utils';
|
|
15
|
-
import React, {ReactElement} from 'react';
|
|
16
|
-
import {useFocusRing} from './useFocusRing';
|
|
17
|
-
|
|
18
|
-
export interface FocusRingProps {
|
|
19
|
-
/** Child element to apply CSS classes to. */
|
|
20
|
-
children: ReactElement,
|
|
21
|
-
/** CSS class to apply when the element is focused. */
|
|
22
|
-
focusClass?: string,
|
|
23
|
-
/** CSS class to apply when the element has keyboard focus. */
|
|
24
|
-
focusRingClass?: string,
|
|
25
|
-
/**
|
|
26
|
-
* Whether to show the focus ring when something
|
|
27
|
-
* inside the container element has focus (true), or
|
|
28
|
-
* only if the container itself has focus (false).
|
|
29
|
-
* @default false
|
|
30
|
-
*/
|
|
31
|
-
within?: boolean,
|
|
32
|
-
/** Whether the element is a text input. */
|
|
33
|
-
isTextInput?: boolean,
|
|
34
|
-
/** Whether the element will be auto focused. */
|
|
35
|
-
autoFocus?: boolean
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* A utility component that applies a CSS class when an element has keyboard focus.
|
|
40
|
-
* Focus rings are visible only when the user is interacting with a keyboard,
|
|
41
|
-
* not with a mouse, touch, or other input methods.
|
|
42
|
-
*/
|
|
43
|
-
export function FocusRing(props: FocusRingProps): React.ReactElement<unknown, string | React.JSXElementConstructor<any>> {
|
|
44
|
-
let {children, focusClass, focusRingClass} = props;
|
|
45
|
-
let {isFocused, isFocusVisible, focusProps} = useFocusRing(props);
|
|
46
|
-
let child = React.Children.only(children);
|
|
47
|
-
|
|
48
|
-
return React.cloneElement(child, mergeProps(child.props as any, {
|
|
49
|
-
...focusProps,
|
|
50
|
-
className: clsx({
|
|
51
|
-
[focusClass || '']: isFocused,
|
|
52
|
-
[focusRingClass || '']: isFocusVisible
|
|
53
|
-
})
|
|
54
|
-
}));
|
|
55
|
-
}
|