@react-aria/radio 3.10.11 → 3.11.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/types.d.ts.map +1 -1
- package/dist/useRadio.main.js +6 -5
- package/dist/useRadio.main.js.map +1 -1
- package/dist/useRadio.mjs +5 -4
- package/dist/useRadio.module.js +5 -4
- package/dist/useRadio.module.js.map +1 -1
- package/package.json +11 -11
- package/src/useRadio.ts +4 -3
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;
|
|
1
|
+
{"mappings":";;;;ACqBA;IACE,2CAA2C;IAC3C,UAAU,EAAE,oBAAoB,gBAAgB,CAAC,CAAC;IAClD,mCAAmC;IACnC,UAAU,EAAE,oBAAoB,gBAAgB,CAAC,CAAC;IAClD,qCAAqC;IACrC,UAAU,EAAE,OAAO,CAAC;IACpB,+CAA+C;IAC/C,UAAU,EAAE,OAAO,CAAC;IACpB,+CAA+C;IAC/C,SAAS,EAAE,OAAO,CAAA;CACnB;AAED;;;;;;GAMG;AACH,yBAAyB,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,eAAe,EAAE,GAAG,EAAE,UAAU,gBAAgB,GAAG,IAAI,CAAC,GAAG,SAAS,CAgF1H;ACnGD,+BAAgC,SAAQ,gBAAgB;IACtD,iDAAiD;IACjD,eAAe,EAAE,aAAa,CAAC;IAC/B,0DAA0D;IAC1D,UAAU,EAAE,aAAa,CAAC;IAC1B,6DAA6D;IAC7D,gBAAgB,EAAE,aAAa,CAAC;IAChC,+DAA+D;IAC/D,iBAAiB,EAAE,aAAa,CAAA;CACjC;AAED;;;;;GAKG;AACH,8BAA8B,KAAK,EAAE,mBAAmB,EAAE,KAAK,EAAE,eAAe,GAAG,cAAc,CAmHhG;AC7ID,YAAY,EAAC,mBAAmB,EAAE,cAAc,EAAC,MAAM,oBAAoB,CAAC;AAC5E,YAAY,EAAC,WAAW,EAAC,MAAM,qBAAqB,CAAC","sources":["packages/@react-aria/radio/src/packages/@react-aria/radio/src/utils.ts","packages/@react-aria/radio/src/packages/@react-aria/radio/src/useRadio.ts","packages/@react-aria/radio/src/packages/@react-aria/radio/src/useRadioGroup.ts","packages/@react-aria/radio/src/packages/@react-aria/radio/src/index.ts","packages/@react-aria/radio/src/index.ts"],"sourcesContent":[null,null,null,null,"/*\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 {useRadio} from './useRadio';\nexport {useRadioGroup} from './useRadioGroup';\nexport type {AriaRadioGroupProps, AriaRadioProps} from '@react-types/radio';\nexport type {Orientation} from '@react-types/shared';\nexport type {RadioAria} from './useRadio';\nexport type {RadioGroupAria} from './useRadioGroup';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
package/dist/useRadio.main.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
var $eeb149278aae5c67$exports = require("./utils.main.js");
|
|
2
2
|
var $gWC9A$reactariautils = require("@react-aria/utils");
|
|
3
|
-
var $gWC9A$reactariafocus = require("@react-aria/focus");
|
|
4
|
-
var $gWC9A$reactariaform = require("@react-aria/form");
|
|
5
3
|
var $gWC9A$reactariainteractions = require("@react-aria/interactions");
|
|
4
|
+
var $gWC9A$reactariaform = require("@react-aria/form");
|
|
6
5
|
|
|
7
6
|
|
|
8
7
|
function $parcel$export(e, n, v, s) {
|
|
@@ -24,7 +23,6 @@ $parcel$export(module.exports, "useRadio", () => $e184702b1b7f1863$export$37b096
|
|
|
24
23
|
|
|
25
24
|
|
|
26
25
|
|
|
27
|
-
|
|
28
26
|
function $e184702b1b7f1863$export$37b0961d2f4751e2(props, state, ref) {
|
|
29
27
|
let { value: value, children: children, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledby } = props;
|
|
30
28
|
const isDisabled = props.isDisabled || state.isDisabled;
|
|
@@ -36,17 +34,20 @@ function $e184702b1b7f1863$export$37b0961d2f4751e2(props, state, ref) {
|
|
|
36
34
|
e.stopPropagation();
|
|
37
35
|
state.setSelectedValue(value);
|
|
38
36
|
};
|
|
37
|
+
// Handle press state for keyboard interactions and cases where labelProps is not used.
|
|
39
38
|
let { pressProps: pressProps, isPressed: isPressed } = (0, $gWC9A$reactariainteractions.usePress)({
|
|
40
39
|
isDisabled: isDisabled
|
|
41
40
|
});
|
|
42
|
-
//
|
|
41
|
+
// Handle press state on the label.
|
|
43
42
|
let { pressProps: labelProps, isPressed: isLabelPressed } = (0, $gWC9A$reactariainteractions.usePress)({
|
|
44
43
|
isDisabled: isDisabled,
|
|
45
44
|
onPress () {
|
|
45
|
+
var _ref_current;
|
|
46
46
|
state.setSelectedValue(value);
|
|
47
|
+
(_ref_current = ref.current) === null || _ref_current === void 0 ? void 0 : _ref_current.focus();
|
|
47
48
|
}
|
|
48
49
|
});
|
|
49
|
-
let { focusableProps: focusableProps } = (0, $gWC9A$
|
|
50
|
+
let { focusableProps: focusableProps } = (0, $gWC9A$reactariainteractions.useFocusable)((0, $gWC9A$reactariautils.mergeProps)(props, {
|
|
50
51
|
onFocus: ()=>state.setLastFocusedValue(value)
|
|
51
52
|
}), ref);
|
|
52
53
|
let interactions = (0, $gWC9A$reactariautils.mergeProps)(pressProps, focusableProps);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;AA+BM,SAAS,0CAAS,KAAqB,EAAE,KAAsB,EAAE,GAAuC;IAC7G,IAAI,SACF,KAAK,YACL,QAAQ,EACR,cAAc,SAAS,EACvB,mBAAmB,cAAc,EAClC,GAAG;I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AC7D,CAAA,GAAA,sCAAgB,EAAE;4BAAC;IAAkB,GAAG,OAAO;IAE/C,OAAO;QACL,YAAY,CAAA,GAAA,gCAAS,EAAE,YAAY;YAAC,SAAS,CAAA,IAAK,EAAE,cAAc;QAAE;QACpE,YAAY,CAAA,GAAA,gCAAS,EAAE,UAAU;YAC/B,GAAG,YAAY;YACf,MAAM;kBACN;sBACA;YACA,UAAU;YACV,UAAU,MAAM,UAAU,IAAI,uBAAuB;qBACrD;mBACA;sBACA;YACA,oBAAoB;gBAClB,KAAK,CAAC,mBAAmB;gBACzB,MAAM,SAAS,GAAG,iBAAiB;gBACnC;aACD,CAAC,MAAM,CAAC,SAAS,IAAI,CAAC,QAAQ;QACjC;oBACA;QACA,YAAY;QACZ,WAAW,aAAa;IAC1B;AACF","sources":["packages/@react-aria/radio/src/useRadio.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 {AriaRadioProps} from '@react-types/radio';\nimport {filterDOMProps, mergeProps, useFormReset} from '@react-aria/utils';\nimport {InputHTMLAttributes, LabelHTMLAttributes} from 'react';\nimport {radioGroupData} from './utils';\nimport {RadioGroupState} from '@react-stately/radio';\nimport {RefObject} from '@react-types/shared';\nimport {useFocusable, usePress} from '@react-aria/interactions';\nimport {useFormValidation} from '@react-aria/form';\n\nexport interface RadioAria {\n /** Props for the label wrapper element. */\n labelProps: LabelHTMLAttributes<HTMLLabelElement>,\n /** Props for the input element. */\n inputProps: InputHTMLAttributes<HTMLInputElement>,\n /** Whether the radio is disabled. */\n isDisabled: boolean,\n /** Whether the radio is currently selected. */\n isSelected: boolean,\n /** Whether the radio is in a pressed state. */\n isPressed: boolean\n}\n\n/**\n * Provides the behavior and accessibility implementation for an individual\n * radio button in a radio group.\n * @param props - Props for the radio.\n * @param state - State for the radio group, as returned by `useRadioGroupState`.\n * @param ref - Ref to the HTML input element.\n */\nexport function useRadio(props: AriaRadioProps, state: RadioGroupState, ref: RefObject<HTMLInputElement | null>): RadioAria {\n let {\n value,\n children,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledby\n } = props;\n\n const isDisabled = props.isDisabled || state.isDisabled;\n\n let hasChildren = children != null;\n let hasAriaLabel = ariaLabel != null || ariaLabelledby != null;\n if (!hasChildren && !hasAriaLabel) {\n console.warn('If you do not provide children, you must specify an aria-label for accessibility');\n }\n\n let checked = state.selectedValue === value;\n\n let onChange = (e) => {\n e.stopPropagation();\n state.setSelectedValue(value);\n };\n\n // Handle press state for keyboard interactions and cases where labelProps is not used.\n let {pressProps, isPressed} = usePress({\n isDisabled\n });\n\n // Handle press state on the label.\n let {pressProps: labelProps, isPressed: isLabelPressed} = usePress({\n isDisabled,\n onPress() {\n state.setSelectedValue(value);\n ref.current?.focus();\n }\n });\n\n let {focusableProps} = useFocusable(mergeProps(props, {\n onFocus: () => state.setLastFocusedValue(value)\n }), ref);\n let interactions = mergeProps(pressProps, focusableProps);\n let domProps = filterDOMProps(props, {labelable: true});\n let tabIndex: number | undefined = -1;\n if (state.selectedValue != null) {\n if (state.selectedValue === value) {\n tabIndex = 0;\n }\n } else if (state.lastFocusedValue === value || state.lastFocusedValue == null) {\n tabIndex = 0;\n }\n if (isDisabled) {\n tabIndex = undefined;\n }\n\n let {name, descriptionId, errorMessageId, validationBehavior} = radioGroupData.get(state)!;\n useFormReset(ref, state.selectedValue, state.setSelectedValue);\n useFormValidation({validationBehavior}, state, ref);\n\n return {\n labelProps: mergeProps(labelProps, {onClick: e => e.preventDefault()}),\n inputProps: mergeProps(domProps, {\n ...interactions,\n type: 'radio',\n name,\n tabIndex,\n disabled: isDisabled,\n required: state.isRequired && validationBehavior === 'native',\n checked,\n value,\n onChange,\n 'aria-describedby': [\n props['aria-describedby'],\n state.isInvalid ? errorMessageId : null,\n descriptionId\n ].filter(Boolean).join(' ') || undefined\n }),\n isDisabled,\n isSelected: checked,\n isPressed: isPressed || isLabelPressed\n };\n}\n"],"names":[],"version":3,"file":"useRadio.main.js.map"}
|
package/dist/useRadio.mjs
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import {radioGroupData as $884aeceb3d67f00f$export$37b65e5b5444d35c} from "./utils.mjs";
|
|
2
2
|
import {mergeProps as $5jJ3f$mergeProps, filterDOMProps as $5jJ3f$filterDOMProps, useFormReset as $5jJ3f$useFormReset} from "@react-aria/utils";
|
|
3
|
-
import {useFocusable as $5jJ3f$useFocusable} from "@react-aria/
|
|
3
|
+
import {usePress as $5jJ3f$usePress, useFocusable as $5jJ3f$useFocusable} from "@react-aria/interactions";
|
|
4
4
|
import {useFormValidation as $5jJ3f$useFormValidation} from "@react-aria/form";
|
|
5
|
-
import {usePress as $5jJ3f$usePress} from "@react-aria/interactions";
|
|
6
5
|
|
|
7
6
|
/*
|
|
8
7
|
* Copyright 2020 Adobe. All rights reserved.
|
|
@@ -18,7 +17,6 @@ import {usePress as $5jJ3f$usePress} from "@react-aria/interactions";
|
|
|
18
17
|
|
|
19
18
|
|
|
20
19
|
|
|
21
|
-
|
|
22
20
|
function $0d5c49892c1215da$export$37b0961d2f4751e2(props, state, ref) {
|
|
23
21
|
let { value: value, children: children, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledby } = props;
|
|
24
22
|
const isDisabled = props.isDisabled || state.isDisabled;
|
|
@@ -30,14 +28,17 @@ function $0d5c49892c1215da$export$37b0961d2f4751e2(props, state, ref) {
|
|
|
30
28
|
e.stopPropagation();
|
|
31
29
|
state.setSelectedValue(value);
|
|
32
30
|
};
|
|
31
|
+
// Handle press state for keyboard interactions and cases where labelProps is not used.
|
|
33
32
|
let { pressProps: pressProps, isPressed: isPressed } = (0, $5jJ3f$usePress)({
|
|
34
33
|
isDisabled: isDisabled
|
|
35
34
|
});
|
|
36
|
-
//
|
|
35
|
+
// Handle press state on the label.
|
|
37
36
|
let { pressProps: labelProps, isPressed: isLabelPressed } = (0, $5jJ3f$usePress)({
|
|
38
37
|
isDisabled: isDisabled,
|
|
39
38
|
onPress () {
|
|
39
|
+
var _ref_current;
|
|
40
40
|
state.setSelectedValue(value);
|
|
41
|
+
(_ref_current = ref.current) === null || _ref_current === void 0 ? void 0 : _ref_current.focus();
|
|
41
42
|
}
|
|
42
43
|
});
|
|
43
44
|
let { focusableProps: focusableProps } = (0, $5jJ3f$useFocusable)((0, $5jJ3f$mergeProps)(props, {
|
package/dist/useRadio.module.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import {radioGroupData as $884aeceb3d67f00f$export$37b65e5b5444d35c} from "./utils.module.js";
|
|
2
2
|
import {mergeProps as $5jJ3f$mergeProps, filterDOMProps as $5jJ3f$filterDOMProps, useFormReset as $5jJ3f$useFormReset} from "@react-aria/utils";
|
|
3
|
-
import {useFocusable as $5jJ3f$useFocusable} from "@react-aria/
|
|
3
|
+
import {usePress as $5jJ3f$usePress, useFocusable as $5jJ3f$useFocusable} from "@react-aria/interactions";
|
|
4
4
|
import {useFormValidation as $5jJ3f$useFormValidation} from "@react-aria/form";
|
|
5
|
-
import {usePress as $5jJ3f$usePress} from "@react-aria/interactions";
|
|
6
5
|
|
|
7
6
|
/*
|
|
8
7
|
* Copyright 2020 Adobe. All rights reserved.
|
|
@@ -18,7 +17,6 @@ import {usePress as $5jJ3f$usePress} from "@react-aria/interactions";
|
|
|
18
17
|
|
|
19
18
|
|
|
20
19
|
|
|
21
|
-
|
|
22
20
|
function $0d5c49892c1215da$export$37b0961d2f4751e2(props, state, ref) {
|
|
23
21
|
let { value: value, children: children, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledby } = props;
|
|
24
22
|
const isDisabled = props.isDisabled || state.isDisabled;
|
|
@@ -30,14 +28,17 @@ function $0d5c49892c1215da$export$37b0961d2f4751e2(props, state, ref) {
|
|
|
30
28
|
e.stopPropagation();
|
|
31
29
|
state.setSelectedValue(value);
|
|
32
30
|
};
|
|
31
|
+
// Handle press state for keyboard interactions and cases where labelProps is not used.
|
|
33
32
|
let { pressProps: pressProps, isPressed: isPressed } = (0, $5jJ3f$usePress)({
|
|
34
33
|
isDisabled: isDisabled
|
|
35
34
|
});
|
|
36
|
-
//
|
|
35
|
+
// Handle press state on the label.
|
|
37
36
|
let { pressProps: labelProps, isPressed: isLabelPressed } = (0, $5jJ3f$usePress)({
|
|
38
37
|
isDisabled: isDisabled,
|
|
39
38
|
onPress () {
|
|
39
|
+
var _ref_current;
|
|
40
40
|
state.setSelectedValue(value);
|
|
41
|
+
(_ref_current = ref.current) === null || _ref_current === void 0 ? void 0 : _ref_current.focus();
|
|
41
42
|
}
|
|
42
43
|
});
|
|
43
44
|
let { focusableProps: focusableProps } = (0, $5jJ3f$useFocusable)((0, $5jJ3f$mergeProps)(props, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;;AAAA;;;;;;;;;;CAUC;;;;AA+BM,SAAS,0CAAS,KAAqB,EAAE,KAAsB,EAAE,GAAuC;IAC7G,IAAI,SACF,KAAK,YACL,QAAQ,EACR,cAAc,SAAS,EACvB,mBAAmB,cAAc,EAClC,GAAG;IAEJ,MAAM,aAAa,MAAM,UAAU,IAAI,MAAM,UAAU;IAEvD,IAAI,cAAc,YAAY;IAC9B,IAAI,eAAe,aAAa,QAAQ,kBAAkB;IAC1D,IAAI,CAAC,eAAe,CAAC,cACnB,QAAQ,IAAI,CAAC;IAGf,IAAI,UAAU,MAAM,aAAa,KAAK;IAEtC,IAAI,WAAW,CAAC;QACd,EAAE,eAAe;QACjB,MAAM,gBAAgB,CAAC;IACzB;IAEA,uFAAuF;IACvF,IAAI,cAAC,UAAU,aAAE,SAA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AK,CAAC,mBAAmB;gBACzB,MAAM,SAAS,GAAG,iBAAiB;gBACnC;aACD,CAAC,MAAM,CAAC,SAAS,IAAI,CAAC,QAAQ;QACjC;oBACA;QACA,YAAY;QACZ,WAAW,aAAa;IAC1B;AACF","sources":["packages/@react-aria/radio/src/useRadio.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 {AriaRadioProps} from '@react-types/radio';\nimport {filterDOMProps, mergeProps, useFormReset} from '@react-aria/utils';\nimport {InputHTMLAttributes, LabelHTMLAttributes} from 'react';\nimport {radioGroupData} from './utils';\nimport {RadioGroupState} from '@react-stately/radio';\nimport {RefObject} from '@react-types/shared';\nimport {useFocusable, usePress} from '@react-aria/interactions';\nimport {useFormValidation} from '@react-aria/form';\n\nexport interface RadioAria {\n /** Props for the label wrapper element. */\n labelProps: LabelHTMLAttributes<HTMLLabelElement>,\n /** Props for the input element. */\n inputProps: InputHTMLAttributes<HTMLInputElement>,\n /** Whether the radio is disabled. */\n isDisabled: boolean,\n /** Whether the radio is currently selected. */\n isSelected: boolean,\n /** Whether the radio is in a pressed state. */\n isPressed: boolean\n}\n\n/**\n * Provides the behavior and accessibility implementation for an individual\n * radio button in a radio group.\n * @param props - Props for the radio.\n * @param state - State for the radio group, as returned by `useRadioGroupState`.\n * @param ref - Ref to the HTML input element.\n */\nexport function useRadio(props: AriaRadioProps, state: RadioGroupState, ref: RefObject<HTMLInputElement | null>): RadioAria {\n let {\n value,\n children,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledby\n } = props;\n\n const isDisabled = props.isDisabled || state.isDisabled;\n\n let hasChildren = children != null;\n let hasAriaLabel = ariaLabel != null || ariaLabelledby != null;\n if (!hasChildren && !hasAriaLabel) {\n console.warn('If you do not provide children, you must specify an aria-label for accessibility');\n }\n\n let checked = state.selectedValue === value;\n\n let onChange = (e) => {\n e.stopPropagation();\n state.setSelectedValue(value);\n };\n\n // Handle press state for keyboard interactions and cases where labelProps is not used.\n let {pressProps, isPressed} = usePress({\n isDisabled\n });\n\n // Handle press state on the label.\n let {pressProps: labelProps, isPressed: isLabelPressed} = usePress({\n isDisabled,\n onPress() {\n state.setSelectedValue(value);\n ref.current?.focus();\n }\n });\n\n let {focusableProps} = useFocusable(mergeProps(props, {\n onFocus: () => state.setLastFocusedValue(value)\n }), ref);\n let interactions = mergeProps(pressProps, focusableProps);\n let domProps = filterDOMProps(props, {labelable: true});\n let tabIndex: number | undefined = -1;\n if (state.selectedValue != null) {\n if (state.selectedValue === value) {\n tabIndex = 0;\n }\n } else if (state.lastFocusedValue === value || state.lastFocusedValue == null) {\n tabIndex = 0;\n }\n if (isDisabled) {\n tabIndex = undefined;\n }\n\n let {name, descriptionId, errorMessageId, validationBehavior} = radioGroupData.get(state)!;\n useFormReset(ref, state.selectedValue, state.setSelectedValue);\n useFormValidation({validationBehavior}, state, ref);\n\n return {\n labelProps: mergeProps(labelProps, {onClick: e => e.preventDefault()}),\n inputProps: mergeProps(domProps, {\n ...interactions,\n type: 'radio',\n name,\n tabIndex,\n disabled: isDisabled,\n required: state.isRequired && validationBehavior === 'native',\n checked,\n value,\n onChange,\n 'aria-describedby': [\n props['aria-describedby'],\n state.isInvalid ? errorMessageId : null,\n descriptionId\n ].filter(Boolean).join(' ') || undefined\n }),\n isDisabled,\n isSelected: checked,\n isPressed: isPressed || isLabelPressed\n };\n}\n"],"names":[],"version":3,"file":"useRadio.module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/radio",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.11.0",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -22,15 +22,15 @@
|
|
|
22
22
|
"url": "https://github.com/adobe/react-spectrum"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@react-aria/focus": "^3.
|
|
26
|
-
"@react-aria/form": "^3.0.
|
|
27
|
-
"@react-aria/i18n": "^3.12.
|
|
28
|
-
"@react-aria/interactions": "^3.
|
|
29
|
-
"@react-aria/label": "^3.7.
|
|
30
|
-
"@react-aria/utils": "^3.
|
|
31
|
-
"@react-stately/radio": "^3.10.
|
|
32
|
-
"@react-types/radio": "^3.8.
|
|
33
|
-
"@react-types/shared": "^3.
|
|
25
|
+
"@react-aria/focus": "^3.20.0",
|
|
26
|
+
"@react-aria/form": "^3.0.13",
|
|
27
|
+
"@react-aria/i18n": "^3.12.6",
|
|
28
|
+
"@react-aria/interactions": "^3.24.0",
|
|
29
|
+
"@react-aria/label": "^3.7.15",
|
|
30
|
+
"@react-aria/utils": "^3.28.0",
|
|
31
|
+
"@react-stately/radio": "^3.10.11",
|
|
32
|
+
"@react-types/radio": "^3.8.7",
|
|
33
|
+
"@react-types/shared": "^3.28.0",
|
|
34
34
|
"@swc/helpers": "^0.5.0"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
"publishConfig": {
|
|
41
41
|
"access": "public"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "4d3c72c94eea2d72eb3a0e7d56000c6ef7e39726"
|
|
44
44
|
}
|
package/src/useRadio.ts
CHANGED
|
@@ -16,9 +16,8 @@ import {InputHTMLAttributes, LabelHTMLAttributes} from 'react';
|
|
|
16
16
|
import {radioGroupData} from './utils';
|
|
17
17
|
import {RadioGroupState} from '@react-stately/radio';
|
|
18
18
|
import {RefObject} from '@react-types/shared';
|
|
19
|
-
import {useFocusable} from '@react-aria/
|
|
19
|
+
import {useFocusable, usePress} from '@react-aria/interactions';
|
|
20
20
|
import {useFormValidation} from '@react-aria/form';
|
|
21
|
-
import {usePress} from '@react-aria/interactions';
|
|
22
21
|
|
|
23
22
|
export interface RadioAria {
|
|
24
23
|
/** Props for the label wrapper element. */
|
|
@@ -63,15 +62,17 @@ export function useRadio(props: AriaRadioProps, state: RadioGroupState, ref: Ref
|
|
|
63
62
|
state.setSelectedValue(value);
|
|
64
63
|
};
|
|
65
64
|
|
|
65
|
+
// Handle press state for keyboard interactions and cases where labelProps is not used.
|
|
66
66
|
let {pressProps, isPressed} = usePress({
|
|
67
67
|
isDisabled
|
|
68
68
|
});
|
|
69
69
|
|
|
70
|
-
//
|
|
70
|
+
// Handle press state on the label.
|
|
71
71
|
let {pressProps: labelProps, isPressed: isLabelPressed} = usePress({
|
|
72
72
|
isDisabled,
|
|
73
73
|
onPress() {
|
|
74
74
|
state.setSelectedValue(value);
|
|
75
|
+
ref.current?.focus();
|
|
75
76
|
}
|
|
76
77
|
});
|
|
77
78
|
|