@react-aria/focus 3.0.0-nightly-641446f65-240905
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/README.md +3 -0
- package/dist/FocusRing.main.js +44 -0
- package/dist/FocusRing.main.js.map +1 -0
- package/dist/FocusRing.mjs +35 -0
- package/dist/FocusRing.module.js +35 -0
- package/dist/FocusRing.module.js.map +1 -0
- package/dist/FocusScope.main.js +748 -0
- package/dist/FocusScope.main.js.map +1 -0
- package/dist/FocusScope.mjs +734 -0
- package/dist/FocusScope.module.js +734 -0
- package/dist/FocusScope.module.js.map +1 -0
- package/dist/focusSafely.main.js +39 -0
- package/dist/focusSafely.main.js.map +1 -0
- package/dist/focusSafely.mjs +34 -0
- package/dist/focusSafely.module.js +34 -0
- package/dist/focusSafely.module.js.map +1 -0
- package/dist/import.mjs +27 -0
- package/dist/isElementVisible.main.js +41 -0
- package/dist/isElementVisible.main.js.map +1 -0
- package/dist/isElementVisible.mjs +36 -0
- package/dist/isElementVisible.module.js +36 -0
- package/dist/isElementVisible.module.js.map +1 -0
- package/dist/main.js +43 -0
- package/dist/main.js.map +1 -0
- package/dist/module.js +27 -0
- package/dist/module.js.map +1 -0
- package/dist/types.d.ts +148 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/useFocusRing.main.js +50 -0
- package/dist/useFocusRing.main.js.map +1 -0
- package/dist/useFocusRing.mjs +45 -0
- package/dist/useFocusRing.module.js +45 -0
- package/dist/useFocusRing.module.js.map +1 -0
- package/dist/useFocusable.main.js +75 -0
- package/dist/useFocusable.main.js.map +1 -0
- package/dist/useFocusable.mjs +65 -0
- package/dist/useFocusable.module.js +65 -0
- package/dist/useFocusable.module.js.map +1 -0
- package/dist/useHasTabbableChild.main.js +62 -0
- package/dist/useHasTabbableChild.main.js.map +1 -0
- package/dist/useHasTabbableChild.mjs +57 -0
- package/dist/useHasTabbableChild.module.js +57 -0
- package/dist/useHasTabbableChild.module.js.map +1 -0
- package/package.json +38 -0
- package/src/FocusRing.tsx +55 -0
- package/src/FocusScope.tsx +988 -0
- package/src/focusSafely.ts +39 -0
- package/src/index.ts +23 -0
- package/src/isElementVisible.ts +69 -0
- package/src/useFocusRing.ts +78 -0
- package/src/useFocusable.tsx +97 -0
- package/src/useHasTabbableChild.ts +66 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import {getFocusableTreeWalker as $9bf71ea28793e738$export$2d6ec8fc375ceafa} from "./FocusScope.mjs";
|
|
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
|
|
@@ -0,0 +1,57 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@react-aria/focus",
|
|
3
|
+
"version": "3.0.0-nightly-641446f65-240905",
|
|
4
|
+
"description": "Spectrum UI components in React",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"main": "dist/main.js",
|
|
7
|
+
"module": "dist/module.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
"types": "./dist/types.d.ts",
|
|
10
|
+
"import": "./dist/import.mjs",
|
|
11
|
+
"require": "./dist/main.js"
|
|
12
|
+
},
|
|
13
|
+
"types": "dist/types.d.ts",
|
|
14
|
+
"source": "src/index.ts",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"src"
|
|
18
|
+
],
|
|
19
|
+
"sideEffects": false,
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "https://github.com/adobe/react-spectrum"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@react-aria/interactions": "^3.0.0-nightly-641446f65-240905",
|
|
26
|
+
"@react-aria/utils": "^3.0.0-nightly-641446f65-240905",
|
|
27
|
+
"@react-types/shared": "^3.0.0-nightly-641446f65-240905",
|
|
28
|
+
"@swc/helpers": "^0.5.0",
|
|
29
|
+
"clsx": "^2.0.0"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
36
|
+
},
|
|
37
|
+
"stableVersion": "3.18.2"
|
|
38
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
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) {
|
|
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
|
+
}
|