@react-aria/radio 3.12.4 → 3.13.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 +2 -4
- package/dist/main.js +3 -5
- package/dist/main.js.map +1 -1
- package/dist/module.js +2 -4
- package/dist/module.js.map +1 -1
- package/dist/types/src/index.d.ts +3 -0
- package/package.json +16 -20
- package/src/index.ts +3 -5
- package/dist/types.d.ts +0 -45
- package/dist/types.d.ts.map +0 -1
- package/dist/useRadio.main.js +0 -112
- package/dist/useRadio.main.js.map +0 -1
- package/dist/useRadio.mjs +0 -107
- package/dist/useRadio.module.js +0 -107
- package/dist/useRadio.module.js.map +0 -1
- package/dist/useRadioGroup.main.js +0 -134
- package/dist/useRadioGroup.main.js.map +0 -1
- package/dist/useRadioGroup.mjs +0 -129
- package/dist/useRadioGroup.module.js +0 -129
- package/dist/useRadioGroup.module.js.map +0 -1
- package/dist/utils.main.js +0 -20
- package/dist/utils.main.js.map +0 -1
- package/dist/utils.mjs +0 -15
- package/dist/utils.module.js +0 -15
- package/dist/utils.module.js.map +0 -1
- package/src/useRadio.ts +0 -149
- package/src/useRadioGroup.ts +0 -160
- package/src/utils.ts +0 -23
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
var $eeb149278aae5c67$exports = require("./utils.main.js");
|
|
2
|
-
var $bNSfM$reactariautils = require("@react-aria/utils");
|
|
3
|
-
var $bNSfM$reactariafocus = require("@react-aria/focus");
|
|
4
|
-
var $bNSfM$reactarialabel = require("@react-aria/label");
|
|
5
|
-
var $bNSfM$reactariainteractions = require("@react-aria/interactions");
|
|
6
|
-
var $bNSfM$reactariai18n = require("@react-aria/i18n");
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
function $parcel$export(e, n, v, s) {
|
|
10
|
-
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
$parcel$export(module.exports, "useRadioGroup", () => $dfcade00a56a6317$export$62b9571f283ff5c2);
|
|
14
|
-
/*
|
|
15
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
16
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
17
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
18
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
19
|
-
*
|
|
20
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
21
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
22
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
23
|
-
* governing permissions and limitations under the License.
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
function $dfcade00a56a6317$export$62b9571f283ff5c2(props, state) {
|
|
31
|
-
let { name: name, form: form, isReadOnly: isReadOnly, isRequired: isRequired, isDisabled: isDisabled, orientation: orientation = 'vertical', validationBehavior: validationBehavior = 'aria' } = props;
|
|
32
|
-
let { direction: direction } = (0, $bNSfM$reactariai18n.useLocale)();
|
|
33
|
-
let { isInvalid: isInvalid, validationErrors: validationErrors, validationDetails: validationDetails } = state.displayValidation;
|
|
34
|
-
let { labelProps: labelProps, fieldProps: fieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $bNSfM$reactarialabel.useField)({
|
|
35
|
-
...props,
|
|
36
|
-
// Radio group is not an HTML input element so it
|
|
37
|
-
// shouldn't be labeled by a <label> element.
|
|
38
|
-
labelElementType: 'span',
|
|
39
|
-
isInvalid: state.isInvalid,
|
|
40
|
-
errorMessage: props.errorMessage || validationErrors
|
|
41
|
-
});
|
|
42
|
-
let domProps = (0, $bNSfM$reactariautils.filterDOMProps)(props, {
|
|
43
|
-
labelable: true
|
|
44
|
-
});
|
|
45
|
-
// When the radio group loses focus, reset the focusable radio to null if
|
|
46
|
-
// there is no selection. This allows tabbing into the group from either
|
|
47
|
-
// direction to go to the first or last radio.
|
|
48
|
-
let { focusWithinProps: focusWithinProps } = (0, $bNSfM$reactariainteractions.useFocusWithin)({
|
|
49
|
-
onBlurWithin (e) {
|
|
50
|
-
var _props_onBlur;
|
|
51
|
-
(_props_onBlur = props.onBlur) === null || _props_onBlur === void 0 ? void 0 : _props_onBlur.call(props, e);
|
|
52
|
-
if (!state.selectedValue) state.setLastFocusedValue(null);
|
|
53
|
-
},
|
|
54
|
-
onFocusWithin: props.onFocus,
|
|
55
|
-
onFocusWithinChange: props.onFocusChange
|
|
56
|
-
});
|
|
57
|
-
let onKeyDown = (e)=>{
|
|
58
|
-
let nextDir;
|
|
59
|
-
switch(e.key){
|
|
60
|
-
case 'ArrowRight':
|
|
61
|
-
if (direction === 'rtl' && orientation !== 'vertical') nextDir = 'prev';
|
|
62
|
-
else nextDir = 'next';
|
|
63
|
-
break;
|
|
64
|
-
case 'ArrowLeft':
|
|
65
|
-
if (direction === 'rtl' && orientation !== 'vertical') nextDir = 'next';
|
|
66
|
-
else nextDir = 'prev';
|
|
67
|
-
break;
|
|
68
|
-
case 'ArrowDown':
|
|
69
|
-
nextDir = 'next';
|
|
70
|
-
break;
|
|
71
|
-
case 'ArrowUp':
|
|
72
|
-
nextDir = 'prev';
|
|
73
|
-
break;
|
|
74
|
-
default:
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
e.preventDefault();
|
|
78
|
-
let walker = (0, $bNSfM$reactariafocus.getFocusableTreeWalker)(e.currentTarget, {
|
|
79
|
-
from: e.target,
|
|
80
|
-
accept: (node)=>node instanceof (0, $bNSfM$reactariautils.getOwnerWindow)(node).HTMLInputElement && node.type === 'radio'
|
|
81
|
-
});
|
|
82
|
-
let nextElem;
|
|
83
|
-
if (nextDir === 'next') {
|
|
84
|
-
nextElem = walker.nextNode();
|
|
85
|
-
if (!nextElem) {
|
|
86
|
-
walker.currentNode = e.currentTarget;
|
|
87
|
-
nextElem = walker.firstChild();
|
|
88
|
-
}
|
|
89
|
-
} else {
|
|
90
|
-
nextElem = walker.previousNode();
|
|
91
|
-
if (!nextElem) {
|
|
92
|
-
walker.currentNode = e.currentTarget;
|
|
93
|
-
nextElem = walker.lastChild();
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
if (nextElem) {
|
|
97
|
-
// Call focus on nextElem so that keyboard navigation scrolls the radio into view
|
|
98
|
-
nextElem.focus();
|
|
99
|
-
state.setSelectedValue(nextElem.value);
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
let groupName = (0, $bNSfM$reactariautils.useId)(name);
|
|
103
|
-
(0, $eeb149278aae5c67$exports.radioGroupData).set(state, {
|
|
104
|
-
name: groupName,
|
|
105
|
-
form: form,
|
|
106
|
-
descriptionId: descriptionProps.id,
|
|
107
|
-
errorMessageId: errorMessageProps.id,
|
|
108
|
-
validationBehavior: validationBehavior
|
|
109
|
-
});
|
|
110
|
-
return {
|
|
111
|
-
radioGroupProps: (0, $bNSfM$reactariautils.mergeProps)(domProps, {
|
|
112
|
-
// https://www.w3.org/TR/wai-aria-1.2/#radiogroup
|
|
113
|
-
role: 'radiogroup',
|
|
114
|
-
onKeyDown: onKeyDown,
|
|
115
|
-
'aria-invalid': state.isInvalid || undefined,
|
|
116
|
-
'aria-errormessage': props['aria-errormessage'],
|
|
117
|
-
'aria-readonly': isReadOnly || undefined,
|
|
118
|
-
'aria-required': isRequired || undefined,
|
|
119
|
-
'aria-disabled': isDisabled || undefined,
|
|
120
|
-
'aria-orientation': orientation,
|
|
121
|
-
...fieldProps,
|
|
122
|
-
...focusWithinProps
|
|
123
|
-
}),
|
|
124
|
-
labelProps: labelProps,
|
|
125
|
-
descriptionProps: descriptionProps,
|
|
126
|
-
errorMessageProps: errorMessageProps,
|
|
127
|
-
isInvalid: isInvalid,
|
|
128
|
-
validationErrors: validationErrors,
|
|
129
|
-
validationDetails: validationDetails
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
|
|
134
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. 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 {AriaRadioGroupProps} from '@react-types/radio';\nimport {DOMAttributes, ValidationResult} from '@react-types/shared';\nimport {filterDOMProps, getOwnerWindow, mergeProps, useId} from '@react-aria/utils';\nimport {getFocusableTreeWalker} from '@react-aria/focus';\nimport {radioGroupData} from './utils';\nimport {RadioGroupState} from '@react-stately/radio';\nimport {useField} from '@react-aria/label';\nimport {useFocusWithin} from '@react-aria/interactions';\nimport {useLocale} from '@react-aria/i18n';\n\nexport interface RadioGroupAria extends ValidationResult {\n /** Props for the radio group wrapper element. */\n radioGroupProps: DOMAttributes,\n /** Props for the radio group's visible label (if any). */\n labelProps: DOMAttributes,\n /** Props for the radio group description element, if any. */\n descriptionProps: DOMAttributes,\n /** Props for the radio group error message element, if any. */\n errorMessageProps: DOMAttributes\n}\n\n/**\n * Provides the behavior and accessibility implementation for a radio group component.\n * Radio groups allow users to select a single item from a list of mutually exclusive options.\n * @param props - Props for the radio group.\n * @param state - State for the radio group, as returned by `useRadioGroupState`.\n */\nexport function useRadioGroup(props: AriaRadioGroupProps, state: RadioGroupState): RadioGroupAria {\n let {\n name,\n form,\n isReadOnly,\n isRequired,\n isDisabled,\n orientation = 'vertical',\n validationBehavior = 'aria'\n } = props;\n let {direction} = useLocale();\n\n let {isInvalid, validationErrors, validationDetails} = state.displayValidation;\n let {labelProps, fieldProps, descriptionProps, errorMessageProps} = useField({\n ...props,\n // Radio group is not an HTML input element so it\n // shouldn't be labeled by a <label> element.\n labelElementType: 'span',\n isInvalid: state.isInvalid,\n errorMessage: props.errorMessage || validationErrors\n });\n\n let domProps = filterDOMProps(props, {labelable: true});\n\n // When the radio group loses focus, reset the focusable radio to null if\n // there is no selection. This allows tabbing into the group from either\n // direction to go to the first or last radio.\n let {focusWithinProps} = useFocusWithin({\n onBlurWithin(e) {\n props.onBlur?.(e);\n if (!state.selectedValue) {\n state.setLastFocusedValue(null);\n }\n },\n onFocusWithin: props.onFocus,\n onFocusWithinChange: props.onFocusChange\n });\n\n let onKeyDown = (e) => {\n let nextDir;\n switch (e.key) {\n case 'ArrowRight':\n if (direction === 'rtl' && orientation !== 'vertical') {\n nextDir = 'prev';\n } else {\n nextDir = 'next';\n }\n break;\n case 'ArrowLeft':\n if (direction === 'rtl' && orientation !== 'vertical') {\n nextDir = 'next';\n } else {\n nextDir = 'prev';\n }\n break;\n case 'ArrowDown':\n nextDir = 'next';\n break;\n case 'ArrowUp':\n nextDir = 'prev';\n break;\n default:\n return;\n }\n e.preventDefault();\n let walker = getFocusableTreeWalker(e.currentTarget, {\n from: e.target,\n accept: (node) => node instanceof getOwnerWindow(node).HTMLInputElement && node.type === 'radio'\n });\n let nextElem;\n if (nextDir === 'next') {\n nextElem = walker.nextNode();\n if (!nextElem) {\n walker.currentNode = e.currentTarget;\n nextElem = walker.firstChild();\n }\n } else {\n nextElem = walker.previousNode();\n if (!nextElem) {\n walker.currentNode = e.currentTarget;\n nextElem = walker.lastChild();\n }\n }\n if (nextElem) {\n // Call focus on nextElem so that keyboard navigation scrolls the radio into view\n nextElem.focus();\n state.setSelectedValue(nextElem.value);\n }\n };\n\n let groupName = useId(name);\n radioGroupData.set(state, {\n name: groupName,\n form,\n descriptionId: descriptionProps.id,\n errorMessageId: errorMessageProps.id,\n validationBehavior\n });\n\n return {\n radioGroupProps: mergeProps(domProps, {\n // https://www.w3.org/TR/wai-aria-1.2/#radiogroup\n role: 'radiogroup',\n onKeyDown,\n 'aria-invalid': state.isInvalid || undefined,\n 'aria-errormessage': props['aria-errormessage'],\n 'aria-readonly': isReadOnly || undefined,\n 'aria-required': isRequired || undefined,\n 'aria-disabled': isDisabled || undefined,\n 'aria-orientation': orientation,\n ...fieldProps,\n ...focusWithinProps\n }),\n labelProps,\n descriptionProps,\n errorMessageProps,\n isInvalid,\n validationErrors,\n validationDetails\n };\n}\n"],"names":[],"version":3,"file":"useRadioGroup.main.js.map"}
|
package/dist/useRadioGroup.mjs
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import {radioGroupData as $884aeceb3d67f00f$export$37b65e5b5444d35c} from "./utils.mjs";
|
|
2
|
-
import {filterDOMProps as $czmJy$filterDOMProps, getOwnerWindow as $czmJy$getOwnerWindow, useId as $czmJy$useId, mergeProps as $czmJy$mergeProps} from "@react-aria/utils";
|
|
3
|
-
import {getFocusableTreeWalker as $czmJy$getFocusableTreeWalker} from "@react-aria/focus";
|
|
4
|
-
import {useField as $czmJy$useField} from "@react-aria/label";
|
|
5
|
-
import {useFocusWithin as $czmJy$useFocusWithin} from "@react-aria/interactions";
|
|
6
|
-
import {useLocale as $czmJy$useLocale} from "@react-aria/i18n";
|
|
7
|
-
|
|
8
|
-
/*
|
|
9
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
10
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
11
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
12
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
13
|
-
*
|
|
14
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
15
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
16
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
17
|
-
* governing permissions and limitations under the License.
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
function $430f30ed08ec25fa$export$62b9571f283ff5c2(props, state) {
|
|
25
|
-
let { name: name, form: form, isReadOnly: isReadOnly, isRequired: isRequired, isDisabled: isDisabled, orientation: orientation = 'vertical', validationBehavior: validationBehavior = 'aria' } = props;
|
|
26
|
-
let { direction: direction } = (0, $czmJy$useLocale)();
|
|
27
|
-
let { isInvalid: isInvalid, validationErrors: validationErrors, validationDetails: validationDetails } = state.displayValidation;
|
|
28
|
-
let { labelProps: labelProps, fieldProps: fieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $czmJy$useField)({
|
|
29
|
-
...props,
|
|
30
|
-
// Radio group is not an HTML input element so it
|
|
31
|
-
// shouldn't be labeled by a <label> element.
|
|
32
|
-
labelElementType: 'span',
|
|
33
|
-
isInvalid: state.isInvalid,
|
|
34
|
-
errorMessage: props.errorMessage || validationErrors
|
|
35
|
-
});
|
|
36
|
-
let domProps = (0, $czmJy$filterDOMProps)(props, {
|
|
37
|
-
labelable: true
|
|
38
|
-
});
|
|
39
|
-
// When the radio group loses focus, reset the focusable radio to null if
|
|
40
|
-
// there is no selection. This allows tabbing into the group from either
|
|
41
|
-
// direction to go to the first or last radio.
|
|
42
|
-
let { focusWithinProps: focusWithinProps } = (0, $czmJy$useFocusWithin)({
|
|
43
|
-
onBlurWithin (e) {
|
|
44
|
-
var _props_onBlur;
|
|
45
|
-
(_props_onBlur = props.onBlur) === null || _props_onBlur === void 0 ? void 0 : _props_onBlur.call(props, e);
|
|
46
|
-
if (!state.selectedValue) state.setLastFocusedValue(null);
|
|
47
|
-
},
|
|
48
|
-
onFocusWithin: props.onFocus,
|
|
49
|
-
onFocusWithinChange: props.onFocusChange
|
|
50
|
-
});
|
|
51
|
-
let onKeyDown = (e)=>{
|
|
52
|
-
let nextDir;
|
|
53
|
-
switch(e.key){
|
|
54
|
-
case 'ArrowRight':
|
|
55
|
-
if (direction === 'rtl' && orientation !== 'vertical') nextDir = 'prev';
|
|
56
|
-
else nextDir = 'next';
|
|
57
|
-
break;
|
|
58
|
-
case 'ArrowLeft':
|
|
59
|
-
if (direction === 'rtl' && orientation !== 'vertical') nextDir = 'next';
|
|
60
|
-
else nextDir = 'prev';
|
|
61
|
-
break;
|
|
62
|
-
case 'ArrowDown':
|
|
63
|
-
nextDir = 'next';
|
|
64
|
-
break;
|
|
65
|
-
case 'ArrowUp':
|
|
66
|
-
nextDir = 'prev';
|
|
67
|
-
break;
|
|
68
|
-
default:
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
e.preventDefault();
|
|
72
|
-
let walker = (0, $czmJy$getFocusableTreeWalker)(e.currentTarget, {
|
|
73
|
-
from: e.target,
|
|
74
|
-
accept: (node)=>node instanceof (0, $czmJy$getOwnerWindow)(node).HTMLInputElement && node.type === 'radio'
|
|
75
|
-
});
|
|
76
|
-
let nextElem;
|
|
77
|
-
if (nextDir === 'next') {
|
|
78
|
-
nextElem = walker.nextNode();
|
|
79
|
-
if (!nextElem) {
|
|
80
|
-
walker.currentNode = e.currentTarget;
|
|
81
|
-
nextElem = walker.firstChild();
|
|
82
|
-
}
|
|
83
|
-
} else {
|
|
84
|
-
nextElem = walker.previousNode();
|
|
85
|
-
if (!nextElem) {
|
|
86
|
-
walker.currentNode = e.currentTarget;
|
|
87
|
-
nextElem = walker.lastChild();
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
if (nextElem) {
|
|
91
|
-
// Call focus on nextElem so that keyboard navigation scrolls the radio into view
|
|
92
|
-
nextElem.focus();
|
|
93
|
-
state.setSelectedValue(nextElem.value);
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
let groupName = (0, $czmJy$useId)(name);
|
|
97
|
-
(0, $884aeceb3d67f00f$export$37b65e5b5444d35c).set(state, {
|
|
98
|
-
name: groupName,
|
|
99
|
-
form: form,
|
|
100
|
-
descriptionId: descriptionProps.id,
|
|
101
|
-
errorMessageId: errorMessageProps.id,
|
|
102
|
-
validationBehavior: validationBehavior
|
|
103
|
-
});
|
|
104
|
-
return {
|
|
105
|
-
radioGroupProps: (0, $czmJy$mergeProps)(domProps, {
|
|
106
|
-
// https://www.w3.org/TR/wai-aria-1.2/#radiogroup
|
|
107
|
-
role: 'radiogroup',
|
|
108
|
-
onKeyDown: onKeyDown,
|
|
109
|
-
'aria-invalid': state.isInvalid || undefined,
|
|
110
|
-
'aria-errormessage': props['aria-errormessage'],
|
|
111
|
-
'aria-readonly': isReadOnly || undefined,
|
|
112
|
-
'aria-required': isRequired || undefined,
|
|
113
|
-
'aria-disabled': isDisabled || undefined,
|
|
114
|
-
'aria-orientation': orientation,
|
|
115
|
-
...fieldProps,
|
|
116
|
-
...focusWithinProps
|
|
117
|
-
}),
|
|
118
|
-
labelProps: labelProps,
|
|
119
|
-
descriptionProps: descriptionProps,
|
|
120
|
-
errorMessageProps: errorMessageProps,
|
|
121
|
-
isInvalid: isInvalid,
|
|
122
|
-
validationErrors: validationErrors,
|
|
123
|
-
validationDetails: validationDetails
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
export {$430f30ed08ec25fa$export$62b9571f283ff5c2 as useRadioGroup};
|
|
129
|
-
//# sourceMappingURL=useRadioGroup.module.js.map
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import {radioGroupData as $884aeceb3d67f00f$export$37b65e5b5444d35c} from "./utils.module.js";
|
|
2
|
-
import {filterDOMProps as $czmJy$filterDOMProps, getOwnerWindow as $czmJy$getOwnerWindow, useId as $czmJy$useId, mergeProps as $czmJy$mergeProps} from "@react-aria/utils";
|
|
3
|
-
import {getFocusableTreeWalker as $czmJy$getFocusableTreeWalker} from "@react-aria/focus";
|
|
4
|
-
import {useField as $czmJy$useField} from "@react-aria/label";
|
|
5
|
-
import {useFocusWithin as $czmJy$useFocusWithin} from "@react-aria/interactions";
|
|
6
|
-
import {useLocale as $czmJy$useLocale} from "@react-aria/i18n";
|
|
7
|
-
|
|
8
|
-
/*
|
|
9
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
10
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
11
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
12
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
13
|
-
*
|
|
14
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
15
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
16
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
17
|
-
* governing permissions and limitations under the License.
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
function $430f30ed08ec25fa$export$62b9571f283ff5c2(props, state) {
|
|
25
|
-
let { name: name, form: form, isReadOnly: isReadOnly, isRequired: isRequired, isDisabled: isDisabled, orientation: orientation = 'vertical', validationBehavior: validationBehavior = 'aria' } = props;
|
|
26
|
-
let { direction: direction } = (0, $czmJy$useLocale)();
|
|
27
|
-
let { isInvalid: isInvalid, validationErrors: validationErrors, validationDetails: validationDetails } = state.displayValidation;
|
|
28
|
-
let { labelProps: labelProps, fieldProps: fieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $czmJy$useField)({
|
|
29
|
-
...props,
|
|
30
|
-
// Radio group is not an HTML input element so it
|
|
31
|
-
// shouldn't be labeled by a <label> element.
|
|
32
|
-
labelElementType: 'span',
|
|
33
|
-
isInvalid: state.isInvalid,
|
|
34
|
-
errorMessage: props.errorMessage || validationErrors
|
|
35
|
-
});
|
|
36
|
-
let domProps = (0, $czmJy$filterDOMProps)(props, {
|
|
37
|
-
labelable: true
|
|
38
|
-
});
|
|
39
|
-
// When the radio group loses focus, reset the focusable radio to null if
|
|
40
|
-
// there is no selection. This allows tabbing into the group from either
|
|
41
|
-
// direction to go to the first or last radio.
|
|
42
|
-
let { focusWithinProps: focusWithinProps } = (0, $czmJy$useFocusWithin)({
|
|
43
|
-
onBlurWithin (e) {
|
|
44
|
-
var _props_onBlur;
|
|
45
|
-
(_props_onBlur = props.onBlur) === null || _props_onBlur === void 0 ? void 0 : _props_onBlur.call(props, e);
|
|
46
|
-
if (!state.selectedValue) state.setLastFocusedValue(null);
|
|
47
|
-
},
|
|
48
|
-
onFocusWithin: props.onFocus,
|
|
49
|
-
onFocusWithinChange: props.onFocusChange
|
|
50
|
-
});
|
|
51
|
-
let onKeyDown = (e)=>{
|
|
52
|
-
let nextDir;
|
|
53
|
-
switch(e.key){
|
|
54
|
-
case 'ArrowRight':
|
|
55
|
-
if (direction === 'rtl' && orientation !== 'vertical') nextDir = 'prev';
|
|
56
|
-
else nextDir = 'next';
|
|
57
|
-
break;
|
|
58
|
-
case 'ArrowLeft':
|
|
59
|
-
if (direction === 'rtl' && orientation !== 'vertical') nextDir = 'next';
|
|
60
|
-
else nextDir = 'prev';
|
|
61
|
-
break;
|
|
62
|
-
case 'ArrowDown':
|
|
63
|
-
nextDir = 'next';
|
|
64
|
-
break;
|
|
65
|
-
case 'ArrowUp':
|
|
66
|
-
nextDir = 'prev';
|
|
67
|
-
break;
|
|
68
|
-
default:
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
e.preventDefault();
|
|
72
|
-
let walker = (0, $czmJy$getFocusableTreeWalker)(e.currentTarget, {
|
|
73
|
-
from: e.target,
|
|
74
|
-
accept: (node)=>node instanceof (0, $czmJy$getOwnerWindow)(node).HTMLInputElement && node.type === 'radio'
|
|
75
|
-
});
|
|
76
|
-
let nextElem;
|
|
77
|
-
if (nextDir === 'next') {
|
|
78
|
-
nextElem = walker.nextNode();
|
|
79
|
-
if (!nextElem) {
|
|
80
|
-
walker.currentNode = e.currentTarget;
|
|
81
|
-
nextElem = walker.firstChild();
|
|
82
|
-
}
|
|
83
|
-
} else {
|
|
84
|
-
nextElem = walker.previousNode();
|
|
85
|
-
if (!nextElem) {
|
|
86
|
-
walker.currentNode = e.currentTarget;
|
|
87
|
-
nextElem = walker.lastChild();
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
if (nextElem) {
|
|
91
|
-
// Call focus on nextElem so that keyboard navigation scrolls the radio into view
|
|
92
|
-
nextElem.focus();
|
|
93
|
-
state.setSelectedValue(nextElem.value);
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
let groupName = (0, $czmJy$useId)(name);
|
|
97
|
-
(0, $884aeceb3d67f00f$export$37b65e5b5444d35c).set(state, {
|
|
98
|
-
name: groupName,
|
|
99
|
-
form: form,
|
|
100
|
-
descriptionId: descriptionProps.id,
|
|
101
|
-
errorMessageId: errorMessageProps.id,
|
|
102
|
-
validationBehavior: validationBehavior
|
|
103
|
-
});
|
|
104
|
-
return {
|
|
105
|
-
radioGroupProps: (0, $czmJy$mergeProps)(domProps, {
|
|
106
|
-
// https://www.w3.org/TR/wai-aria-1.2/#radiogroup
|
|
107
|
-
role: 'radiogroup',
|
|
108
|
-
onKeyDown: onKeyDown,
|
|
109
|
-
'aria-invalid': state.isInvalid || undefined,
|
|
110
|
-
'aria-errormessage': props['aria-errormessage'],
|
|
111
|
-
'aria-readonly': isReadOnly || undefined,
|
|
112
|
-
'aria-required': isRequired || undefined,
|
|
113
|
-
'aria-disabled': isDisabled || undefined,
|
|
114
|
-
'aria-orientation': orientation,
|
|
115
|
-
...fieldProps,
|
|
116
|
-
...focusWithinProps
|
|
117
|
-
}),
|
|
118
|
-
labelProps: labelProps,
|
|
119
|
-
descriptionProps: descriptionProps,
|
|
120
|
-
errorMessageProps: errorMessageProps,
|
|
121
|
-
isInvalid: isInvalid,
|
|
122
|
-
validationErrors: validationErrors,
|
|
123
|
-
validationDetails: validationDetails
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
export {$430f30ed08ec25fa$export$62b9571f283ff5c2 as useRadioGroup};
|
|
129
|
-
//# sourceMappingURL=useRadioGroup.module.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":";;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;AA6BM,SAAS,0CAAc,KAA0B,EAAE,KAAsB;IAC9E,IAAI,QACF,IAAI,QACJ,I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AS,gBAAgB,CAAA,GAAA,qBAAa,EAAE,MAAM,gBAAgB,IAAI,KAAK,IAAI,KAAK;QAC3F;QACA,IAAI;QACJ,IAAI,YAAY,QAAQ;YACtB,WAAW,OAAO,QAAQ;YAC1B,IAAI,CAAC,UAAU;gBACb,OAAO,WAAW,GAAG,EAAE,aAAa;gBACpC,WAAW,OAAO,UAAU;YAC9B;QACF,OAAO;YACL,WAAW,OAAO,YAAY;YAC9B,IAAI,CAAC,UAAU;gBACb,OAAO,WAAW,GAAG,EAAE,aAAa;gBACpC,WAAW,OAAO,SAAS;YAC7B;QACF;QACA,IAAI,UAAU;YACZ,iFAAiF;YACjF,SAAS,KAAK;YACd,MAAM,gBAAgB,CAAC,SAAS,KAAK;QACvC;IACF;IAEA,IAAI,YAAY,CAAA,GAAA,YAAI,EAAE;IACtB,CAAA,GAAA,yCAAa,EAAE,GAAG,CAAC,OAAO;QACxB,MAAM;cACN;QACA,eAAe,iBAAiB,EAAE;QAClC,gBAAgB,kBAAkB,EAAE;4BACpC;IACF;IAEA,OAAO;QACL,iBAAiB,CAAA,GAAA,iBAAS,EAAE,UAAU;YACpC,iDAAiD;YACjD,MAAM;uBACN;YACA,gBAAgB,MAAM,SAAS,IAAI;YACnC,qBAAqB,KAAK,CAAC,oBAAoB;YAC/C,iBAAiB,cAAc;YAC/B,iBAAiB,cAAc;YAC/B,iBAAiB,cAAc;YAC/B,oBAAoB;YACpB,GAAG,UAAU;YACb,GAAG,gBAAgB;QACrB;oBACA;0BACA;2BACA;mBACA;0BACA;2BACA;IACF;AACF","sources":["packages/@react-aria/radio/src/useRadioGroup.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 */\n\nimport {AriaRadioGroupProps} from '@react-types/radio';\nimport {DOMAttributes, ValidationResult} from '@react-types/shared';\nimport {filterDOMProps, getOwnerWindow, mergeProps, useId} from '@react-aria/utils';\nimport {getFocusableTreeWalker} from '@react-aria/focus';\nimport {radioGroupData} from './utils';\nimport {RadioGroupState} from '@react-stately/radio';\nimport {useField} from '@react-aria/label';\nimport {useFocusWithin} from '@react-aria/interactions';\nimport {useLocale} from '@react-aria/i18n';\n\nexport interface RadioGroupAria extends ValidationResult {\n /** Props for the radio group wrapper element. */\n radioGroupProps: DOMAttributes,\n /** Props for the radio group's visible label (if any). */\n labelProps: DOMAttributes,\n /** Props for the radio group description element, if any. */\n descriptionProps: DOMAttributes,\n /** Props for the radio group error message element, if any. */\n errorMessageProps: DOMAttributes\n}\n\n/**\n * Provides the behavior and accessibility implementation for a radio group component.\n * Radio groups allow users to select a single item from a list of mutually exclusive options.\n * @param props - Props for the radio group.\n * @param state - State for the radio group, as returned by `useRadioGroupState`.\n */\nexport function useRadioGroup(props: AriaRadioGroupProps, state: RadioGroupState): RadioGroupAria {\n let {\n name,\n form,\n isReadOnly,\n isRequired,\n isDisabled,\n orientation = 'vertical',\n validationBehavior = 'aria'\n } = props;\n let {direction} = useLocale();\n\n let {isInvalid, validationErrors, validationDetails} = state.displayValidation;\n let {labelProps, fieldProps, descriptionProps, errorMessageProps} = useField({\n ...props,\n // Radio group is not an HTML input element so it\n // shouldn't be labeled by a <label> element.\n labelElementType: 'span',\n isInvalid: state.isInvalid,\n errorMessage: props.errorMessage || validationErrors\n });\n\n let domProps = filterDOMProps(props, {labelable: true});\n\n // When the radio group loses focus, reset the focusable radio to null if\n // there is no selection. This allows tabbing into the group from either\n // direction to go to the first or last radio.\n let {focusWithinProps} = useFocusWithin({\n onBlurWithin(e) {\n props.onBlur?.(e);\n if (!state.selectedValue) {\n state.setLastFocusedValue(null);\n }\n },\n onFocusWithin: props.onFocus,\n onFocusWithinChange: props.onFocusChange\n });\n\n let onKeyDown = (e) => {\n let nextDir;\n switch (e.key) {\n case 'ArrowRight':\n if (direction === 'rtl' && orientation !== 'vertical') {\n nextDir = 'prev';\n } else {\n nextDir = 'next';\n }\n break;\n case 'ArrowLeft':\n if (direction === 'rtl' && orientation !== 'vertical') {\n nextDir = 'next';\n } else {\n nextDir = 'prev';\n }\n break;\n case 'ArrowDown':\n nextDir = 'next';\n break;\n case 'ArrowUp':\n nextDir = 'prev';\n break;\n default:\n return;\n }\n e.preventDefault();\n let walker = getFocusableTreeWalker(e.currentTarget, {\n from: e.target,\n accept: (node) => node instanceof getOwnerWindow(node).HTMLInputElement && node.type === 'radio'\n });\n let nextElem;\n if (nextDir === 'next') {\n nextElem = walker.nextNode();\n if (!nextElem) {\n walker.currentNode = e.currentTarget;\n nextElem = walker.firstChild();\n }\n } else {\n nextElem = walker.previousNode();\n if (!nextElem) {\n walker.currentNode = e.currentTarget;\n nextElem = walker.lastChild();\n }\n }\n if (nextElem) {\n // Call focus on nextElem so that keyboard navigation scrolls the radio into view\n nextElem.focus();\n state.setSelectedValue(nextElem.value);\n }\n };\n\n let groupName = useId(name);\n radioGroupData.set(state, {\n name: groupName,\n form,\n descriptionId: descriptionProps.id,\n errorMessageId: errorMessageProps.id,\n validationBehavior\n });\n\n return {\n radioGroupProps: mergeProps(domProps, {\n // https://www.w3.org/TR/wai-aria-1.2/#radiogroup\n role: 'radiogroup',\n onKeyDown,\n 'aria-invalid': state.isInvalid || undefined,\n 'aria-errormessage': props['aria-errormessage'],\n 'aria-readonly': isReadOnly || undefined,\n 'aria-required': isRequired || undefined,\n 'aria-disabled': isDisabled || undefined,\n 'aria-orientation': orientation,\n ...fieldProps,\n ...focusWithinProps\n }),\n labelProps,\n descriptionProps,\n errorMessageProps,\n isInvalid,\n validationErrors,\n validationDetails\n };\n}\n"],"names":[],"version":3,"file":"useRadioGroup.module.js.map"}
|
package/dist/utils.main.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
function $parcel$export(e, n, v, s) {
|
|
3
|
-
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
$parcel$export(module.exports, "radioGroupData", () => $eeb149278aae5c67$export$37b65e5b5444d35c);
|
|
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
|
-
*/ const $eeb149278aae5c67$export$37b65e5b5444d35c = new WeakMap();
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
//# sourceMappingURL=utils.main.js.map
|
package/dist/utils.main.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":";;;;;;AAAA;;;;;;;;;;CAUC,GAYM,MAAM,4CAA2D,IAAI","sources":["packages/@react-aria/radio/src/utils.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 */\n\nimport {RadioGroupState} from '@react-stately/radio';\n\ninterface RadioGroupData {\n name: string,\n form: string | undefined,\n descriptionId: string | undefined,\n errorMessageId: string | undefined,\n validationBehavior: 'aria' | 'native'\n}\n\nexport const radioGroupData: WeakMap<RadioGroupState, RadioGroupData> = new WeakMap<RadioGroupState, RadioGroupData>();\n"],"names":[],"version":3,"file":"utils.main.js.map"}
|
package/dist/utils.mjs
DELETED
|
@@ -1,15 +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
|
-
*/ const $884aeceb3d67f00f$export$37b65e5b5444d35c = new WeakMap();
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export {$884aeceb3d67f00f$export$37b65e5b5444d35c as radioGroupData};
|
|
15
|
-
//# sourceMappingURL=utils.module.js.map
|
package/dist/utils.module.js
DELETED
|
@@ -1,15 +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
|
-
*/ const $884aeceb3d67f00f$export$37b65e5b5444d35c = new WeakMap();
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export {$884aeceb3d67f00f$export$37b65e5b5444d35c as radioGroupData};
|
|
15
|
-
//# sourceMappingURL=utils.module.js.map
|
package/dist/utils.module.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":"AAAA;;;;;;;;;;CAUC,GAYM,MAAM,4CAA2D,IAAI","sources":["packages/@react-aria/radio/src/utils.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 */\n\nimport {RadioGroupState} from '@react-stately/radio';\n\ninterface RadioGroupData {\n name: string,\n form: string | undefined,\n descriptionId: string | undefined,\n errorMessageId: string | undefined,\n validationBehavior: 'aria' | 'native'\n}\n\nexport const radioGroupData: WeakMap<RadioGroupState, RadioGroupData> = new WeakMap<RadioGroupState, RadioGroupData>();\n"],"names":[],"version":3,"file":"utils.module.js.map"}
|
package/src/useRadio.ts
DELETED
|
@@ -1,149 +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 {AriaRadioProps} from '@react-types/radio';
|
|
14
|
-
import {filterDOMProps, mergeProps, useFormReset} from '@react-aria/utils';
|
|
15
|
-
import {InputHTMLAttributes, LabelHTMLAttributes, useMemo} from 'react';
|
|
16
|
-
import {radioGroupData} from './utils';
|
|
17
|
-
import {RadioGroupState} from '@react-stately/radio';
|
|
18
|
-
import {RefObject} from '@react-types/shared';
|
|
19
|
-
import {useFocusable, usePress} from '@react-aria/interactions';
|
|
20
|
-
import {useFormValidation} from '@react-aria/form';
|
|
21
|
-
|
|
22
|
-
export interface RadioAria {
|
|
23
|
-
/** Props for the label wrapper element. */
|
|
24
|
-
labelProps: LabelHTMLAttributes<HTMLLabelElement>,
|
|
25
|
-
/** Props for the input element. */
|
|
26
|
-
inputProps: InputHTMLAttributes<HTMLInputElement>,
|
|
27
|
-
/** Whether the radio is disabled. */
|
|
28
|
-
isDisabled: boolean,
|
|
29
|
-
/** Whether the radio is currently selected. */
|
|
30
|
-
isSelected: boolean,
|
|
31
|
-
/** Whether the radio is in a pressed state. */
|
|
32
|
-
isPressed: boolean
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Provides the behavior and accessibility implementation for an individual
|
|
37
|
-
* radio button in a radio group.
|
|
38
|
-
* @param props - Props for the radio.
|
|
39
|
-
* @param state - State for the radio group, as returned by `useRadioGroupState`.
|
|
40
|
-
* @param ref - Ref to the HTML input element.
|
|
41
|
-
*/
|
|
42
|
-
export function useRadio(props: AriaRadioProps, state: RadioGroupState, ref: RefObject<HTMLInputElement | null>): RadioAria {
|
|
43
|
-
let {
|
|
44
|
-
value,
|
|
45
|
-
children,
|
|
46
|
-
'aria-label': ariaLabel,
|
|
47
|
-
'aria-labelledby': ariaLabelledby,
|
|
48
|
-
onPressStart,
|
|
49
|
-
onPressEnd,
|
|
50
|
-
onPressChange,
|
|
51
|
-
onPress,
|
|
52
|
-
onPressUp,
|
|
53
|
-
onClick
|
|
54
|
-
} = props;
|
|
55
|
-
|
|
56
|
-
const isDisabled = props.isDisabled || state.isDisabled;
|
|
57
|
-
|
|
58
|
-
let hasChildren = children != null;
|
|
59
|
-
let hasAriaLabel = ariaLabel != null || ariaLabelledby != null;
|
|
60
|
-
if (!hasChildren && !hasAriaLabel && process.env.NODE_ENV !== 'production') {
|
|
61
|
-
console.warn('If you do not provide children, you must specify an aria-label for accessibility');
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
let checked = state.selectedValue === value;
|
|
65
|
-
|
|
66
|
-
let onChange = (e) => {
|
|
67
|
-
e.stopPropagation();
|
|
68
|
-
state.setSelectedValue(value);
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
// Handle press state for keyboard interactions and cases where labelProps is not used.
|
|
72
|
-
let {pressProps, isPressed} = usePress({
|
|
73
|
-
onPressStart,
|
|
74
|
-
onPressEnd,
|
|
75
|
-
onPressChange,
|
|
76
|
-
onPress,
|
|
77
|
-
onPressUp,
|
|
78
|
-
onClick,
|
|
79
|
-
isDisabled
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
// Handle press state on the label.
|
|
83
|
-
let {pressProps: labelProps, isPressed: isLabelPressed} = usePress({
|
|
84
|
-
onPressStart,
|
|
85
|
-
onPressEnd,
|
|
86
|
-
onPressChange,
|
|
87
|
-
onPressUp,
|
|
88
|
-
onClick,
|
|
89
|
-
isDisabled,
|
|
90
|
-
onPress(e) {
|
|
91
|
-
onPress?.(e);
|
|
92
|
-
state.setSelectedValue(value);
|
|
93
|
-
ref.current?.focus();
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
let {focusableProps} = useFocusable(mergeProps(props, {
|
|
98
|
-
onFocus: () => state.setLastFocusedValue(value)
|
|
99
|
-
}), ref);
|
|
100
|
-
let interactions = mergeProps(pressProps, focusableProps);
|
|
101
|
-
let domProps = filterDOMProps(props, {labelable: true});
|
|
102
|
-
let tabIndex: number | undefined = -1;
|
|
103
|
-
if (state.selectedValue != null) {
|
|
104
|
-
if (state.selectedValue === value) {
|
|
105
|
-
tabIndex = 0;
|
|
106
|
-
}
|
|
107
|
-
} else if (state.lastFocusedValue === value || state.lastFocusedValue == null) {
|
|
108
|
-
tabIndex = 0;
|
|
109
|
-
}
|
|
110
|
-
if (isDisabled) {
|
|
111
|
-
tabIndex = undefined;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
let {name, form, descriptionId, errorMessageId, validationBehavior} = radioGroupData.get(state)!;
|
|
115
|
-
useFormReset(ref, state.defaultSelectedValue, state.setSelectedValue);
|
|
116
|
-
useFormValidation({validationBehavior}, state, ref);
|
|
117
|
-
|
|
118
|
-
return {
|
|
119
|
-
labelProps: mergeProps(
|
|
120
|
-
labelProps,
|
|
121
|
-
useMemo(() => ({
|
|
122
|
-
onClick: e => e.preventDefault(),
|
|
123
|
-
|
|
124
|
-
// Prevent label from being focused when mouse down on it.
|
|
125
|
-
// Note, this does not prevent the input from being focused in the `click` event.
|
|
126
|
-
onMouseDown: e => e.preventDefault()
|
|
127
|
-
}), [])),
|
|
128
|
-
inputProps: mergeProps(domProps, {
|
|
129
|
-
...interactions,
|
|
130
|
-
type: 'radio',
|
|
131
|
-
name,
|
|
132
|
-
form,
|
|
133
|
-
tabIndex,
|
|
134
|
-
disabled: isDisabled,
|
|
135
|
-
required: state.isRequired && validationBehavior === 'native',
|
|
136
|
-
checked,
|
|
137
|
-
value,
|
|
138
|
-
onChange,
|
|
139
|
-
'aria-describedby': [
|
|
140
|
-
props['aria-describedby'],
|
|
141
|
-
state.isInvalid ? errorMessageId : null,
|
|
142
|
-
descriptionId
|
|
143
|
-
].filter(Boolean).join(' ') || undefined
|
|
144
|
-
}),
|
|
145
|
-
isDisabled,
|
|
146
|
-
isSelected: checked,
|
|
147
|
-
isPressed: isPressed || isLabelPressed
|
|
148
|
-
};
|
|
149
|
-
}
|