@react-aria/actiongroup 3.4.4-nightly.3598 → 3.4.4-nightly.3600
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/main.js +57 -28
- package/dist/main.js.map +1 -1
- package/dist/module.mjs +57 -28
- package/dist/module.mjs.map +1 -1
- package/package.json +12 -12
package/dist/main.js
CHANGED
|
@@ -9,43 +9,62 @@ function $parcel$export(e, n, v, s) {
|
|
|
9
9
|
|
|
10
10
|
$parcel$export(module.exports, "useActionGroup", () => $ceb684449a137553$export$f4bf8d43c16de704);
|
|
11
11
|
$parcel$export(module.exports, "useActionGroupItem", () => $44b92e5de834b44e$export$9597202bd3099a29);
|
|
12
|
-
|
|
12
|
+
/*
|
|
13
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
14
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
15
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
16
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
17
|
+
*
|
|
18
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
19
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
20
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
21
|
+
* governing permissions and limitations under the License.
|
|
22
|
+
*/ /*
|
|
23
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
24
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
25
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
26
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
27
|
+
*
|
|
28
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
29
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
30
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
31
|
+
* governing permissions and limitations under the License.
|
|
32
|
+
*/
|
|
13
33
|
|
|
14
34
|
|
|
15
35
|
const $ceb684449a137553$var$BUTTON_GROUP_ROLES = {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
36
|
+
"none": "toolbar",
|
|
37
|
+
"single": "radiogroup",
|
|
38
|
+
"multiple": "toolbar"
|
|
19
39
|
};
|
|
20
40
|
function $ceb684449a137553$export$f4bf8d43c16de704(props, state, ref) {
|
|
21
|
-
let { isDisabled: isDisabled , orientation: orientation =
|
|
41
|
+
let { isDisabled: isDisabled , orientation: orientation = "horizontal" } = props;
|
|
22
42
|
let allKeys = [
|
|
23
43
|
...state.collection.getKeys()
|
|
24
44
|
];
|
|
25
|
-
if (!allKeys.some((key)=>!state.disabledKeys.has(key)
|
|
26
|
-
|
|
27
|
-
let
|
|
28
|
-
let
|
|
29
|
-
let flipDirection = direction === 'rtl' && orientation === 'horizontal';
|
|
45
|
+
if (!allKeys.some((key)=>!state.disabledKeys.has(key))) isDisabled = true;
|
|
46
|
+
let { direction: direction } = (0, $hjKwo$reactariai18n.useLocale)();
|
|
47
|
+
let focusManager = (0, $hjKwo$reactariafocus.createFocusManager)(ref);
|
|
48
|
+
let flipDirection = direction === "rtl" && orientation === "horizontal";
|
|
30
49
|
let onKeyDown = (e)=>{
|
|
31
50
|
if (!e.currentTarget.contains(e.target)) return;
|
|
32
51
|
switch(e.key){
|
|
33
|
-
case
|
|
34
|
-
case
|
|
52
|
+
case "ArrowRight":
|
|
53
|
+
case "ArrowDown":
|
|
35
54
|
e.preventDefault();
|
|
36
55
|
e.stopPropagation();
|
|
37
|
-
if (e.key ===
|
|
56
|
+
if (e.key === "ArrowRight" && flipDirection) focusManager.focusPrevious({
|
|
38
57
|
wrap: true
|
|
39
58
|
});
|
|
40
59
|
else focusManager.focusNext({
|
|
41
60
|
wrap: true
|
|
42
61
|
});
|
|
43
62
|
break;
|
|
44
|
-
case
|
|
45
|
-
case
|
|
63
|
+
case "ArrowLeft":
|
|
64
|
+
case "ArrowUp":
|
|
46
65
|
e.preventDefault();
|
|
47
66
|
e.stopPropagation();
|
|
48
|
-
if (e.key ===
|
|
67
|
+
if (e.key === "ArrowLeft" && flipDirection) focusManager.focusNext({
|
|
49
68
|
wrap: true
|
|
50
69
|
});
|
|
51
70
|
else focusManager.focusPrevious({
|
|
@@ -57,36 +76,46 @@ function $ceb684449a137553$export$f4bf8d43c16de704(props, state, ref) {
|
|
|
57
76
|
let role = $ceb684449a137553$var$BUTTON_GROUP_ROLES[state.selectionManager.selectionMode];
|
|
58
77
|
return {
|
|
59
78
|
actionGroupProps: {
|
|
60
|
-
|
|
79
|
+
...(0, $hjKwo$reactariautils.filterDOMProps)(props, {
|
|
61
80
|
labelable: true
|
|
62
81
|
}),
|
|
63
82
|
role: role,
|
|
64
|
-
|
|
65
|
-
|
|
83
|
+
"aria-orientation": role === "toolbar" ? orientation : null,
|
|
84
|
+
"aria-disabled": isDisabled,
|
|
66
85
|
onKeyDown: onKeyDown
|
|
67
86
|
}
|
|
68
87
|
};
|
|
69
88
|
}
|
|
70
89
|
|
|
71
90
|
|
|
72
|
-
|
|
91
|
+
/*
|
|
92
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
93
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
94
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
95
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
96
|
+
*
|
|
97
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
98
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
99
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
100
|
+
* governing permissions and limitations under the License.
|
|
101
|
+
*/
|
|
73
102
|
|
|
74
103
|
const $44b92e5de834b44e$var$BUTTON_ROLES = {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
104
|
+
"none": null,
|
|
105
|
+
"single": "radio",
|
|
106
|
+
"multiple": "checkbox"
|
|
78
107
|
};
|
|
79
108
|
function $44b92e5de834b44e$export$9597202bd3099a29(props, state, ref) {
|
|
80
109
|
let selectionMode = state.selectionManager.selectionMode;
|
|
81
110
|
let buttonProps = {
|
|
82
111
|
role: $44b92e5de834b44e$var$BUTTON_ROLES[selectionMode]
|
|
83
112
|
};
|
|
84
|
-
if (selectionMode !==
|
|
113
|
+
if (selectionMode !== "none") {
|
|
85
114
|
let isSelected = state.selectionManager.isSelected(props.key);
|
|
86
|
-
buttonProps[
|
|
115
|
+
buttonProps["aria-checked"] = isSelected;
|
|
87
116
|
}
|
|
88
117
|
let isFocused = props.key === state.selectionManager.focusedKey;
|
|
89
|
-
let lastRender = $hjKwo$react.useRef({
|
|
118
|
+
let lastRender = (0, $hjKwo$react.useRef)({
|
|
90
119
|
isFocused: isFocused,
|
|
91
120
|
state: state
|
|
92
121
|
});
|
|
@@ -96,13 +125,13 @@ function $44b92e5de834b44e$export$9597202bd3099a29(props, state, ref) {
|
|
|
96
125
|
};
|
|
97
126
|
// If the focused item is removed from the DOM, reset the focused key to null.
|
|
98
127
|
// eslint-disable-next-line arrow-body-style
|
|
99
|
-
$hjKwo$react.useEffect(()=>{
|
|
128
|
+
(0, $hjKwo$react.useEffect)(()=>{
|
|
100
129
|
return ()=>{
|
|
101
130
|
if (lastRender.current.isFocused) lastRender.current.state.selectionManager.setFocusedKey(null);
|
|
102
131
|
};
|
|
103
132
|
}, []);
|
|
104
133
|
return {
|
|
105
|
-
buttonProps: $hjKwo$reactariautils.mergeProps(buttonProps, {
|
|
134
|
+
buttonProps: (0, $hjKwo$reactariautils.mergeProps)(buttonProps, {
|
|
106
135
|
tabIndex: isFocused || state.selectionManager.focusedKey == null ? 0 : -1,
|
|
107
136
|
onFocus () {
|
|
108
137
|
state.selectionManager.setFocusedKey(props.key);
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;;;;;;;;AAAA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roup/src/useActionGroup.ts","packages/@react-aria/actiongroup/src/useActionGroupItem.ts"],"sourcesContent":["/*\n * Copyright 2020 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 */\nexport type {ActionGroupAria} from './useActionGroup';\nexport {useActionGroup} from './useActionGroup';\nexport {useActionGroupItem} from './useActionGroupItem';\nexport type {AriaActionGroupProps} from '@react-types/actiongroup';\nexport type {ActionGroupItemAria, AriaActionGroupItemProps} from './useActionGroupItem';\n","/*\n * Copyright 2020 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 {AriaActionGroupProps} from '@react-types/actiongroup';\nimport {createFocusManager} from '@react-aria/focus';\nimport {DOMAttributes, FocusableElement} from '@react-types/shared';\nimport {filterDOMProps} from '@react-aria/utils';\nimport {ListState} from '@react-stately/list';\nimport {Orientation} from '@react-types/shared';\nimport {RefObject} from 'react';\nimport {useLocale} from '@react-aria/i18n';\n\nconst BUTTON_GROUP_ROLES = {\n 'none': 'toolbar',\n 'single': 'radiogroup',\n 'multiple': 'toolbar'\n};\n\nexport interface ActionGroupAria {\n actionGroupProps: DOMAttributes\n}\n\nexport function useActionGroup<T>(props: AriaActionGroupProps<T>, state: ListState<T>, ref: RefObject<FocusableElement>): ActionGroupAria {\n let {\n isDisabled,\n orientation = 'horizontal' as Orientation\n } = props;\n let allKeys = [...state.collection.getKeys()];\n if (!allKeys.some(key => !state.disabledKeys.has(key))) {\n isDisabled = true;\n }\n\n let {direction} = useLocale();\n let focusManager = createFocusManager(ref);\n let flipDirection = direction === 'rtl' && orientation === 'horizontal';\n let onKeyDown = (e) => {\n if (!e.currentTarget.contains(e.target)) {\n return;\n }\n\n switch (e.key) {\n case 'ArrowRight':\n case 'ArrowDown':\n e.preventDefault();\n e.stopPropagation();\n if (e.key === 'ArrowRight' && flipDirection) {\n focusManager.focusPrevious({wrap: true});\n } else {\n focusManager.focusNext({wrap: true});\n }\n break;\n case 'ArrowLeft':\n case 'ArrowUp':\n e.preventDefault();\n e.stopPropagation();\n if (e.key === 'ArrowLeft' && flipDirection) {\n focusManager.focusNext({wrap: true});\n } else {\n focusManager.focusPrevious({wrap: true});\n }\n break;\n }\n };\n\n let role = BUTTON_GROUP_ROLES[state.selectionManager.selectionMode];\n return {\n actionGroupProps: {\n ...filterDOMProps(props, {labelable: true}),\n role,\n 'aria-orientation': role === 'toolbar' ? orientation : null,\n 'aria-disabled': isDisabled,\n onKeyDown\n }\n };\n}\n","/*\n * Copyright 2020 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 {DOMAttributes, FocusableElement} from '@react-types/shared';\nimport {Key, RefObject, useEffect, useRef} from 'react';\nimport {ListState} from '@react-stately/list';\nimport {mergeProps} from '@react-aria/utils';\nimport {PressProps} from '@react-aria/interactions';\n\nexport interface AriaActionGroupItemProps {\n key: Key\n}\n\nexport interface ActionGroupItemAria {\n buttonProps: DOMAttributes & PressProps\n}\n\nconst BUTTON_ROLES = {\n 'none': null,\n 'single': 'radio',\n 'multiple': 'checkbox'\n};\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport function useActionGroupItem<T>(props: AriaActionGroupItemProps, state: ListState<T>, ref?: RefObject<FocusableElement>): ActionGroupItemAria {\n let selectionMode = state.selectionManager.selectionMode;\n let buttonProps = {\n role: BUTTON_ROLES[selectionMode]\n };\n\n if (selectionMode !== 'none') {\n let isSelected = state.selectionManager.isSelected(props.key);\n buttonProps['aria-checked'] = isSelected;\n }\n\n let isFocused = props.key === state.selectionManager.focusedKey;\n let lastRender = useRef({isFocused, state});\n lastRender.current = {isFocused, state};\n\n // If the focused item is removed from the DOM, reset the focused key to null.\n // eslint-disable-next-line arrow-body-style\n useEffect(() => {\n return () => {\n if (lastRender.current.isFocused) {\n lastRender.current.state.selectionManager.setFocusedKey(null);\n }\n };\n }, []);\n\n return {\n buttonProps: mergeProps(buttonProps, {\n tabIndex: isFocused || state.selectionManager.focusedKey == null ? 0 : -1,\n onFocus() {\n state.selectionManager.setFocusedKey(props.key);\n },\n onPress() {\n state.selectionManager.select(props.key);\n }\n })\n };\n}\n"],"names":[],"version":3,"file":"main.js.map"}
|
package/dist/module.mjs
CHANGED
|
@@ -3,43 +3,62 @@ import {filterDOMProps as $1oG4F$filterDOMProps, mergeProps as $1oG4F$mergeProps
|
|
|
3
3
|
import {useLocale as $1oG4F$useLocale} from "@react-aria/i18n";
|
|
4
4
|
import {useRef as $1oG4F$useRef, useEffect as $1oG4F$useEffect} from "react";
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
/*
|
|
7
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
8
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
9
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
10
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
13
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
14
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
15
|
+
* governing permissions and limitations under the License.
|
|
16
|
+
*/ /*
|
|
17
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
18
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
19
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
20
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
21
|
+
*
|
|
22
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
23
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
24
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
25
|
+
* governing permissions and limitations under the License.
|
|
26
|
+
*/
|
|
7
27
|
|
|
8
28
|
|
|
9
29
|
const $304ac34015d4535d$var$BUTTON_GROUP_ROLES = {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
30
|
+
"none": "toolbar",
|
|
31
|
+
"single": "radiogroup",
|
|
32
|
+
"multiple": "toolbar"
|
|
13
33
|
};
|
|
14
34
|
function $304ac34015d4535d$export$f4bf8d43c16de704(props, state, ref) {
|
|
15
|
-
let { isDisabled: isDisabled , orientation: orientation =
|
|
35
|
+
let { isDisabled: isDisabled , orientation: orientation = "horizontal" } = props;
|
|
16
36
|
let allKeys = [
|
|
17
37
|
...state.collection.getKeys()
|
|
18
38
|
];
|
|
19
|
-
if (!allKeys.some((key)=>!state.disabledKeys.has(key)
|
|
20
|
-
|
|
21
|
-
let
|
|
22
|
-
let
|
|
23
|
-
let flipDirection = direction === 'rtl' && orientation === 'horizontal';
|
|
39
|
+
if (!allKeys.some((key)=>!state.disabledKeys.has(key))) isDisabled = true;
|
|
40
|
+
let { direction: direction } = (0, $1oG4F$useLocale)();
|
|
41
|
+
let focusManager = (0, $1oG4F$createFocusManager)(ref);
|
|
42
|
+
let flipDirection = direction === "rtl" && orientation === "horizontal";
|
|
24
43
|
let onKeyDown = (e)=>{
|
|
25
44
|
if (!e.currentTarget.contains(e.target)) return;
|
|
26
45
|
switch(e.key){
|
|
27
|
-
case
|
|
28
|
-
case
|
|
46
|
+
case "ArrowRight":
|
|
47
|
+
case "ArrowDown":
|
|
29
48
|
e.preventDefault();
|
|
30
49
|
e.stopPropagation();
|
|
31
|
-
if (e.key ===
|
|
50
|
+
if (e.key === "ArrowRight" && flipDirection) focusManager.focusPrevious({
|
|
32
51
|
wrap: true
|
|
33
52
|
});
|
|
34
53
|
else focusManager.focusNext({
|
|
35
54
|
wrap: true
|
|
36
55
|
});
|
|
37
56
|
break;
|
|
38
|
-
case
|
|
39
|
-
case
|
|
57
|
+
case "ArrowLeft":
|
|
58
|
+
case "ArrowUp":
|
|
40
59
|
e.preventDefault();
|
|
41
60
|
e.stopPropagation();
|
|
42
|
-
if (e.key ===
|
|
61
|
+
if (e.key === "ArrowLeft" && flipDirection) focusManager.focusNext({
|
|
43
62
|
wrap: true
|
|
44
63
|
});
|
|
45
64
|
else focusManager.focusPrevious({
|
|
@@ -51,36 +70,46 @@ function $304ac34015d4535d$export$f4bf8d43c16de704(props, state, ref) {
|
|
|
51
70
|
let role = $304ac34015d4535d$var$BUTTON_GROUP_ROLES[state.selectionManager.selectionMode];
|
|
52
71
|
return {
|
|
53
72
|
actionGroupProps: {
|
|
54
|
-
|
|
73
|
+
...(0, $1oG4F$filterDOMProps)(props, {
|
|
55
74
|
labelable: true
|
|
56
75
|
}),
|
|
57
76
|
role: role,
|
|
58
|
-
|
|
59
|
-
|
|
77
|
+
"aria-orientation": role === "toolbar" ? orientation : null,
|
|
78
|
+
"aria-disabled": isDisabled,
|
|
60
79
|
onKeyDown: onKeyDown
|
|
61
80
|
}
|
|
62
81
|
};
|
|
63
82
|
}
|
|
64
83
|
|
|
65
84
|
|
|
66
|
-
|
|
85
|
+
/*
|
|
86
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
87
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
88
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
89
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
90
|
+
*
|
|
91
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
92
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
93
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
94
|
+
* governing permissions and limitations under the License.
|
|
95
|
+
*/
|
|
67
96
|
|
|
68
97
|
const $f0ac0fb73c3ec062$var$BUTTON_ROLES = {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
98
|
+
"none": null,
|
|
99
|
+
"single": "radio",
|
|
100
|
+
"multiple": "checkbox"
|
|
72
101
|
};
|
|
73
102
|
function $f0ac0fb73c3ec062$export$9597202bd3099a29(props, state, ref) {
|
|
74
103
|
let selectionMode = state.selectionManager.selectionMode;
|
|
75
104
|
let buttonProps = {
|
|
76
105
|
role: $f0ac0fb73c3ec062$var$BUTTON_ROLES[selectionMode]
|
|
77
106
|
};
|
|
78
|
-
if (selectionMode !==
|
|
107
|
+
if (selectionMode !== "none") {
|
|
79
108
|
let isSelected = state.selectionManager.isSelected(props.key);
|
|
80
|
-
buttonProps[
|
|
109
|
+
buttonProps["aria-checked"] = isSelected;
|
|
81
110
|
}
|
|
82
111
|
let isFocused = props.key === state.selectionManager.focusedKey;
|
|
83
|
-
let lastRender = $1oG4F$useRef({
|
|
112
|
+
let lastRender = (0, $1oG4F$useRef)({
|
|
84
113
|
isFocused: isFocused,
|
|
85
114
|
state: state
|
|
86
115
|
});
|
|
@@ -90,13 +119,13 @@ function $f0ac0fb73c3ec062$export$9597202bd3099a29(props, state, ref) {
|
|
|
90
119
|
};
|
|
91
120
|
// If the focused item is removed from the DOM, reset the focused key to null.
|
|
92
121
|
// eslint-disable-next-line arrow-body-style
|
|
93
|
-
$1oG4F$useEffect(()=>{
|
|
122
|
+
(0, $1oG4F$useEffect)(()=>{
|
|
94
123
|
return ()=>{
|
|
95
124
|
if (lastRender.current.isFocused) lastRender.current.state.selectionManager.setFocusedKey(null);
|
|
96
125
|
};
|
|
97
126
|
}, []);
|
|
98
127
|
return {
|
|
99
|
-
buttonProps: $1oG4F$mergeProps(buttonProps, {
|
|
128
|
+
buttonProps: (0, $1oG4F$mergeProps)(buttonProps, {
|
|
100
129
|
tabIndex: isFocused || state.selectionManager.focusedKey == null ? 0 : -1,
|
|
101
130
|
onFocus () {
|
|
102
131
|
state.selectionManager.setFocusedKey(props.key);
|
package/dist/module.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC,GAED;;;AASA,MAAM,2CAAqB;IACzB,QAAQ;IACR,UAAU;IACV,YAAY;AACd;AAMO,SAAS,0CAAkB,KAA8B,EAAE,KAAmB,EAAE,GAAgC,EAAmB;IACxI,IAAI,cACF,WAAU,eACV,cAAc,eACf,GAAG;IACJ,IAAI,UAAU;WAAI,MAAM,UAAU,CAAC,OAAO;KAAG;IAC7C,IAAI,CAAC,QAAQ,IAAI,CAAC,CAAA,MAAO,CAAC,MAAM,YAAY,CAAC,GAAG,CAAC,OAC/C,aAAa,IAAI;IAGnB,IAAI,aAAC,UAAS,EAAC,GAAG,CAAA,GAAA,gBAAS,AAAD;IAC1B,IAAI,eAAe,CAAA,GAAA,yBAAiB,EAAE;IACtC,IAAI,gBAAgB,cAAc,SAAS,gBAAgB;IAC3D,IAAI,YAAY,CAAC,IAAM;QACrB,IAAI,CAAC,EAAE,aAAa,CAAC,QAAQ,CAAC,EAAE,MAAM,GACpC;QAGF,OAAQ,EAAE,GAAG;YACX,KAAK;YACL,KAAK;gBACH,EAAE,cAAc;gBAChB,EAAE,eAAe;gBACjB,IAAI,EAAE,GAA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GAAA,gBAAS,AAAD,EAAE,IAAM;QACd,OAAO,IAAM;YACX,IAAI,WAAW,OAAO,CAAC,SAAS,EAC9B,WAAW,OAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC,aAAa,CAAC,IAAI;QAEhE;IACF,GAAG,EAAE;IAEL,OAAO;QACL,aAAa,CAAA,GAAA,iBAAU,AAAD,EAAE,aAAa;YACnC,UAAU,aAAa,MAAM,gBAAgB,CAAC,UAAU,IAAI,IAAI,GAAG,IAAI,EAAE;YACzE,WAAU;gBACR,MAAM,gBAAgB,CAAC,aAAa,CAAC,MAAM,GAAG;YAChD;YACA,WAAU;gBACR,MAAM,gBAAgB,CAAC,MAAM,CAAC,MAAM,GAAG;YACzC;QACF;IACF;AACF;","sources":["packages/@react-aria/actiongroup/src/index.ts","packages/@react-aria/actiongroup/src/useActionGroup.ts","packages/@react-aria/actiongroup/src/useActionGroupItem.ts"],"sourcesContent":["/*\n * Copyright 2020 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 */\nexport type {ActionGroupAria} from './useActionGroup';\nexport {useActionGroup} from './useActionGroup';\nexport {useActionGroupItem} from './useActionGroupItem';\nexport type {AriaActionGroupProps} from '@react-types/actiongroup';\nexport type {ActionGroupItemAria, AriaActionGroupItemProps} from './useActionGroupItem';\n","/*\n * Copyright 2020 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 {AriaActionGroupProps} from '@react-types/actiongroup';\nimport {createFocusManager} from '@react-aria/focus';\nimport {DOMAttributes, FocusableElement} from '@react-types/shared';\nimport {filterDOMProps} from '@react-aria/utils';\nimport {ListState} from '@react-stately/list';\nimport {Orientation} from '@react-types/shared';\nimport {RefObject} from 'react';\nimport {useLocale} from '@react-aria/i18n';\n\nconst BUTTON_GROUP_ROLES = {\n 'none': 'toolbar',\n 'single': 'radiogroup',\n 'multiple': 'toolbar'\n};\n\nexport interface ActionGroupAria {\n actionGroupProps: DOMAttributes\n}\n\nexport function useActionGroup<T>(props: AriaActionGroupProps<T>, state: ListState<T>, ref: RefObject<FocusableElement>): ActionGroupAria {\n let {\n isDisabled,\n orientation = 'horizontal' as Orientation\n } = props;\n let allKeys = [...state.collection.getKeys()];\n if (!allKeys.some(key => !state.disabledKeys.has(key))) {\n isDisabled = true;\n }\n\n let {direction} = useLocale();\n let focusManager = createFocusManager(ref);\n let flipDirection = direction === 'rtl' && orientation === 'horizontal';\n let onKeyDown = (e) => {\n if (!e.currentTarget.contains(e.target)) {\n return;\n }\n\n switch (e.key) {\n case 'ArrowRight':\n case 'ArrowDown':\n e.preventDefault();\n e.stopPropagation();\n if (e.key === 'ArrowRight' && flipDirection) {\n focusManager.focusPrevious({wrap: true});\n } else {\n focusManager.focusNext({wrap: true});\n }\n break;\n case 'ArrowLeft':\n case 'ArrowUp':\n e.preventDefault();\n e.stopPropagation();\n if (e.key === 'ArrowLeft' && flipDirection) {\n focusManager.focusNext({wrap: true});\n } else {\n focusManager.focusPrevious({wrap: true});\n }\n break;\n }\n };\n\n let role = BUTTON_GROUP_ROLES[state.selectionManager.selectionMode];\n return {\n actionGroupProps: {\n ...filterDOMProps(props, {labelable: true}),\n role,\n 'aria-orientation': role === 'toolbar' ? orientation : null,\n 'aria-disabled': isDisabled,\n onKeyDown\n }\n };\n}\n","/*\n * Copyright 2020 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 {DOMAttributes, FocusableElement} from '@react-types/shared';\nimport {Key, RefObject, useEffect, useRef} from 'react';\nimport {ListState} from '@react-stately/list';\nimport {mergeProps} from '@react-aria/utils';\nimport {PressProps} from '@react-aria/interactions';\n\nexport interface AriaActionGroupItemProps {\n key: Key\n}\n\nexport interface ActionGroupItemAria {\n buttonProps: DOMAttributes & PressProps\n}\n\nconst BUTTON_ROLES = {\n 'none': null,\n 'single': 'radio',\n 'multiple': 'checkbox'\n};\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport function useActionGroupItem<T>(props: AriaActionGroupItemProps, state: ListState<T>, ref?: RefObject<FocusableElement>): ActionGroupItemAria {\n let selectionMode = state.selectionManager.selectionMode;\n let buttonProps = {\n role: BUTTON_ROLES[selectionMode]\n };\n\n if (selectionMode !== 'none') {\n let isSelected = state.selectionManager.isSelected(props.key);\n buttonProps['aria-checked'] = isSelected;\n }\n\n let isFocused = props.key === state.selectionManager.focusedKey;\n let lastRender = useRef({isFocused, state});\n lastRender.current = {isFocused, state};\n\n // If the focused item is removed from the DOM, reset the focused key to null.\n // eslint-disable-next-line arrow-body-style\n useEffect(() => {\n return () => {\n if (lastRender.current.isFocused) {\n lastRender.current.state.selectionManager.setFocusedKey(null);\n }\n };\n }, []);\n\n return {\n buttonProps: mergeProps(buttonProps, {\n tabIndex: isFocused || state.selectionManager.focusedKey == null ? 0 : -1,\n onFocus() {\n state.selectionManager.setFocusedKey(props.key);\n },\n onPress() {\n state.selectionManager.select(props.key);\n }\n })\n };\n}\n"],"names":[],"version":3,"file":"module.mjs.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/actiongroup",
|
|
3
|
-
"version": "3.4.4-nightly.
|
|
3
|
+
"version": "3.4.4-nightly.3600+bfce84fee",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -22,16 +22,16 @@
|
|
|
22
22
|
"url": "https://github.com/adobe/react-spectrum"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@
|
|
26
|
-
"@react-aria/
|
|
27
|
-
"@react-aria/
|
|
28
|
-
"@react-aria/
|
|
29
|
-
"@react-aria/
|
|
30
|
-
"@react-
|
|
31
|
-
"@react-stately/
|
|
32
|
-
"@react-
|
|
33
|
-
"@react-types/
|
|
34
|
-
"@
|
|
25
|
+
"@react-aria/focus": "3.0.0-nightly.1900+bfce84fee",
|
|
26
|
+
"@react-aria/i18n": "3.0.0-nightly.1900+bfce84fee",
|
|
27
|
+
"@react-aria/interactions": "3.0.0-nightly.1900+bfce84fee",
|
|
28
|
+
"@react-aria/selection": "3.0.0-nightly.1900+bfce84fee",
|
|
29
|
+
"@react-aria/utils": "3.0.0-nightly.1900+bfce84fee",
|
|
30
|
+
"@react-stately/collections": "3.0.0-nightly.1900+bfce84fee",
|
|
31
|
+
"@react-stately/list": "3.6.1-nightly.3600+bfce84fee",
|
|
32
|
+
"@react-types/actiongroup": "3.3.6-nightly.3600+bfce84fee",
|
|
33
|
+
"@react-types/shared": "3.0.0-nightly.1900+bfce84fee",
|
|
34
|
+
"@swc/helpers": "^0.4.14"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0"
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"publishConfig": {
|
|
40
40
|
"access": "public"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "bfce84fee12a027d9cbc38b43e1747e3e4b4b169"
|
|
43
43
|
}
|