@react-aria/radio 3.4.2 → 3.5.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 +197 -0
- package/package.json +15 -10
package/dist/import.mjs
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import {mergeProps as $4vDl6$mergeProps, filterDOMProps as $4vDl6$filterDOMProps, useId as $4vDl6$useId} from "@react-aria/utils";
|
|
2
|
+
import {useFocusable as $4vDl6$useFocusable, getFocusableTreeWalker as $4vDl6$getFocusableTreeWalker} from "@react-aria/focus";
|
|
3
|
+
import {usePress as $4vDl6$usePress, useFocusWithin as $4vDl6$useFocusWithin} from "@react-aria/interactions";
|
|
4
|
+
import {useField as $4vDl6$useField} from "@react-aria/label";
|
|
5
|
+
import {useLocale as $4vDl6$useLocale} from "@react-aria/i18n";
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
9
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
10
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
11
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
14
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
15
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
16
|
+
* governing permissions and limitations under the License.
|
|
17
|
+
*/ /*
|
|
18
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
19
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
20
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
21
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
22
|
+
*
|
|
23
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
24
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
25
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
26
|
+
* governing permissions and limitations under the License.
|
|
27
|
+
*/
|
|
28
|
+
/*
|
|
29
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
30
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
31
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
32
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
33
|
+
*
|
|
34
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
35
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
36
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
37
|
+
* governing permissions and limitations under the License.
|
|
38
|
+
*/ const $884aeceb3d67f00f$export$3b7b268d09480394 = new WeakMap();
|
|
39
|
+
const $884aeceb3d67f00f$export$8e8b214e06dd397d = new WeakMap();
|
|
40
|
+
const $884aeceb3d67f00f$export$61c8d3f0151e21b2 = new WeakMap();
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
function $0d5c49892c1215da$export$37b0961d2f4751e2(props, state, ref) {
|
|
46
|
+
let { value: value , children: children , "aria-label": ariaLabel , "aria-labelledby": ariaLabelledby } = props;
|
|
47
|
+
const isDisabled = props.isDisabled || state.isDisabled;
|
|
48
|
+
let hasChildren = children != null;
|
|
49
|
+
let hasAriaLabel = ariaLabel != null || ariaLabelledby != null;
|
|
50
|
+
if (!hasChildren && !hasAriaLabel) console.warn("If you do not provide children, you must specify an aria-label for accessibility");
|
|
51
|
+
let checked = state.selectedValue === value;
|
|
52
|
+
let onChange = (e)=>{
|
|
53
|
+
e.stopPropagation();
|
|
54
|
+
state.setSelectedValue(value);
|
|
55
|
+
};
|
|
56
|
+
let { pressProps: pressProps } = (0, $4vDl6$usePress)({
|
|
57
|
+
isDisabled: isDisabled
|
|
58
|
+
});
|
|
59
|
+
let { focusableProps: focusableProps } = (0, $4vDl6$useFocusable)((0, $4vDl6$mergeProps)(props, {
|
|
60
|
+
onFocus: ()=>state.setLastFocusedValue(value)
|
|
61
|
+
}), ref);
|
|
62
|
+
let interactions = (0, $4vDl6$mergeProps)(pressProps, focusableProps);
|
|
63
|
+
let domProps = (0, $4vDl6$filterDOMProps)(props, {
|
|
64
|
+
labelable: true
|
|
65
|
+
});
|
|
66
|
+
let tabIndex = state.lastFocusedValue === value || state.lastFocusedValue == null ? 0 : -1;
|
|
67
|
+
if (isDisabled) tabIndex = undefined;
|
|
68
|
+
return {
|
|
69
|
+
inputProps: (0, $4vDl6$mergeProps)(domProps, {
|
|
70
|
+
...interactions,
|
|
71
|
+
type: "radio",
|
|
72
|
+
name: (0, $884aeceb3d67f00f$export$3b7b268d09480394).get(state),
|
|
73
|
+
tabIndex: tabIndex,
|
|
74
|
+
disabled: isDisabled,
|
|
75
|
+
checked: checked,
|
|
76
|
+
value: value,
|
|
77
|
+
onChange: onChange,
|
|
78
|
+
"aria-describedby": [
|
|
79
|
+
state.validationState === "invalid" ? (0, $884aeceb3d67f00f$export$61c8d3f0151e21b2).get(state) : null,
|
|
80
|
+
(0, $884aeceb3d67f00f$export$8e8b214e06dd397d).get(state)
|
|
81
|
+
].filter(Boolean).join(" ") || undefined
|
|
82
|
+
}),
|
|
83
|
+
isDisabled: isDisabled,
|
|
84
|
+
isSelected: checked
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
/*
|
|
90
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
91
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
92
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
93
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
94
|
+
*
|
|
95
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
96
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
97
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
98
|
+
* governing permissions and limitations under the License.
|
|
99
|
+
*/
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
function $430f30ed08ec25fa$export$62b9571f283ff5c2(props, state) {
|
|
106
|
+
let { name: name , validationState: validationState , isReadOnly: isReadOnly , isRequired: isRequired , isDisabled: isDisabled , orientation: orientation = "vertical" } = props;
|
|
107
|
+
let { direction: direction } = (0, $4vDl6$useLocale)();
|
|
108
|
+
let { labelProps: labelProps , fieldProps: fieldProps , descriptionProps: descriptionProps , errorMessageProps: errorMessageProps } = (0, $4vDl6$useField)({
|
|
109
|
+
...props,
|
|
110
|
+
// Radio group is not an HTML input element so it
|
|
111
|
+
// shouldn't be labeled by a <label> element.
|
|
112
|
+
labelElementType: "span"
|
|
113
|
+
});
|
|
114
|
+
(0, $884aeceb3d67f00f$export$8e8b214e06dd397d).set(state, descriptionProps.id);
|
|
115
|
+
(0, $884aeceb3d67f00f$export$61c8d3f0151e21b2).set(state, errorMessageProps.id);
|
|
116
|
+
let domProps = (0, $4vDl6$filterDOMProps)(props, {
|
|
117
|
+
labelable: true
|
|
118
|
+
});
|
|
119
|
+
// When the radio group loses focus, reset the focusable radio to null if
|
|
120
|
+
// there is no selection. This allows tabbing into the group from either
|
|
121
|
+
// direction to go to the first or last radio.
|
|
122
|
+
let { focusWithinProps: focusWithinProps } = (0, $4vDl6$useFocusWithin)({
|
|
123
|
+
onBlurWithin () {
|
|
124
|
+
if (!state.selectedValue) state.setLastFocusedValue(null);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
let onKeyDown = (e)=>{
|
|
128
|
+
let nextDir;
|
|
129
|
+
switch(e.key){
|
|
130
|
+
case "ArrowRight":
|
|
131
|
+
if (direction === "rtl" && orientation !== "vertical") nextDir = "prev";
|
|
132
|
+
else nextDir = "next";
|
|
133
|
+
break;
|
|
134
|
+
case "ArrowLeft":
|
|
135
|
+
if (direction === "rtl" && orientation !== "vertical") nextDir = "next";
|
|
136
|
+
else nextDir = "prev";
|
|
137
|
+
break;
|
|
138
|
+
case "ArrowDown":
|
|
139
|
+
nextDir = "next";
|
|
140
|
+
break;
|
|
141
|
+
case "ArrowUp":
|
|
142
|
+
nextDir = "prev";
|
|
143
|
+
break;
|
|
144
|
+
default:
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
e.preventDefault();
|
|
148
|
+
let walker = (0, $4vDl6$getFocusableTreeWalker)(e.currentTarget, {
|
|
149
|
+
from: e.target
|
|
150
|
+
});
|
|
151
|
+
let nextElem;
|
|
152
|
+
if (nextDir === "next") {
|
|
153
|
+
nextElem = walker.nextNode();
|
|
154
|
+
if (!nextElem) {
|
|
155
|
+
walker.currentNode = e.currentTarget;
|
|
156
|
+
nextElem = walker.firstChild();
|
|
157
|
+
}
|
|
158
|
+
} else {
|
|
159
|
+
nextElem = walker.previousNode();
|
|
160
|
+
if (!nextElem) {
|
|
161
|
+
walker.currentNode = e.currentTarget;
|
|
162
|
+
nextElem = walker.lastChild();
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (nextElem) {
|
|
166
|
+
// Call focus on nextElem so that keyboard navigation scrolls the radio into view
|
|
167
|
+
nextElem.focus();
|
|
168
|
+
state.setSelectedValue(nextElem.value);
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
let groupName = (0, $4vDl6$useId)(name);
|
|
172
|
+
(0, $884aeceb3d67f00f$export$3b7b268d09480394).set(state, groupName);
|
|
173
|
+
return {
|
|
174
|
+
radioGroupProps: (0, $4vDl6$mergeProps)(domProps, {
|
|
175
|
+
// https://www.w3.org/TR/wai-aria-1.2/#radiogroup
|
|
176
|
+
role: "radiogroup",
|
|
177
|
+
onKeyDown: onKeyDown,
|
|
178
|
+
"aria-invalid": validationState === "invalid" || undefined,
|
|
179
|
+
"aria-errormessage": props["aria-errormessage"],
|
|
180
|
+
"aria-readonly": isReadOnly || undefined,
|
|
181
|
+
"aria-required": isRequired || undefined,
|
|
182
|
+
"aria-disabled": isDisabled || undefined,
|
|
183
|
+
"aria-orientation": orientation,
|
|
184
|
+
...fieldProps,
|
|
185
|
+
...focusWithinProps
|
|
186
|
+
}),
|
|
187
|
+
labelProps: labelProps,
|
|
188
|
+
descriptionProps: descriptionProps,
|
|
189
|
+
errorMessageProps: errorMessageProps
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
export {$0d5c49892c1215da$export$37b0961d2f4751e2 as useRadio, $430f30ed08ec25fa$export$62b9571f283ff5c2 as useRadioGroup};
|
|
197
|
+
//# sourceMappingURL=module.js.map
|
package/package.json
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/radio",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
7
7
|
"module": "dist/module.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
"types": "./dist/types.d.ts",
|
|
10
|
+
"import": "./dist/import.mjs",
|
|
11
|
+
"require": "./dist/main.js"
|
|
12
|
+
},
|
|
8
13
|
"types": "dist/types.d.ts",
|
|
9
14
|
"source": "src/index.ts",
|
|
10
15
|
"files": [
|
|
@@ -17,14 +22,14 @@
|
|
|
17
22
|
"url": "https://github.com/adobe/react-spectrum"
|
|
18
23
|
},
|
|
19
24
|
"dependencies": {
|
|
20
|
-
"@react-aria/focus": "^3.
|
|
21
|
-
"@react-aria/i18n": "^3.
|
|
22
|
-
"@react-aria/interactions": "^3.
|
|
23
|
-
"@react-aria/label": "^3.
|
|
24
|
-
"@react-aria/utils": "^3.
|
|
25
|
-
"@react-stately/radio": "^3.
|
|
26
|
-
"@react-types/radio": "^3.
|
|
27
|
-
"@react-types/shared": "^3.
|
|
25
|
+
"@react-aria/focus": "^3.11.0",
|
|
26
|
+
"@react-aria/i18n": "^3.7.0",
|
|
27
|
+
"@react-aria/interactions": "^3.14.0",
|
|
28
|
+
"@react-aria/label": "^3.5.0",
|
|
29
|
+
"@react-aria/utils": "^3.15.0",
|
|
30
|
+
"@react-stately/radio": "^3.7.0",
|
|
31
|
+
"@react-types/radio": "^3.4.0",
|
|
32
|
+
"@react-types/shared": "^3.17.0",
|
|
28
33
|
"@swc/helpers": "^0.4.14"
|
|
29
34
|
},
|
|
30
35
|
"peerDependencies": {
|
|
@@ -33,5 +38,5 @@
|
|
|
33
38
|
"publishConfig": {
|
|
34
39
|
"access": "public"
|
|
35
40
|
},
|
|
36
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "a0efee84aa178cb1a202951dfd6d8de02b292307"
|
|
37
42
|
}
|