@tamagui/radio-headless 3.0.0-beta.922.1 → 3.0.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/cjs/useRadioGroup.cjs +8 -3
- package/dist/cjs/useRadioGroup.native.cjs +8 -3
- package/dist/cjs/useRadioGroup.native.js +8 -3
- package/dist/cjs/useRadioGroup.native.js.map +1 -1
- package/dist/esm/useRadioGroup.mjs +8 -3
- package/dist/esm/useRadioGroup.mjs.map +1 -1
- package/dist/esm/useRadioGroup.native.js +8 -3
- package/dist/esm/useRadioGroup.native.js.map +1 -1
- package/dist/jsx/useRadioGroup.mjs +8 -3
- package/dist/jsx/useRadioGroup.mjs.map +1 -1
- package/dist/jsx/useRadioGroup.native.cjs +8 -3
- package/dist/jsx/useRadioGroup.native.js +8 -3
- package/dist/jsx/useRadioGroup.native.js.map +1 -1
- package/package.json +16 -13
- package/src/useRadioGroup.tsx +31 -16
- package/types/useRadioGroup.d.ts +53 -4
- package/types/useRadioGroup.d.ts.map +1 -1
|
@@ -139,12 +139,17 @@ const useRadioGroupItem = (params) => {
|
|
|
139
139
|
}
|
|
140
140
|
}),
|
|
141
141
|
...import_constants.isWeb && {
|
|
142
|
-
onKeyDown: (0, import_helpers.composeEventHandlers)(
|
|
143
|
-
if (
|
|
142
|
+
onKeyDown: (0, import_helpers.composeEventHandlers)((event) => {
|
|
143
|
+
if ("key" in event) onKeyDown?.(event);
|
|
144
|
+
}, (event) => {
|
|
145
|
+
const { key } = event.nativeEvent;
|
|
146
|
+
if (key === "Enter" || key === " ") {
|
|
144
147
|
if (!checked) onChange?.(value);
|
|
145
148
|
}
|
|
146
149
|
}),
|
|
147
|
-
onFocus: (0, import_helpers.composeEventHandlers)(
|
|
150
|
+
onFocus: (0, import_helpers.composeEventHandlers)((event) => {
|
|
151
|
+
if ("relatedTarget" in event) onFocus?.(event);
|
|
152
|
+
}, () => {
|
|
148
153
|
if (isArrowKeyPressedRef.current) ref.current?.click();
|
|
149
154
|
})
|
|
150
155
|
}
|
|
@@ -157,12 +157,17 @@ var useRadioGroupItem = function(params) {
|
|
|
157
157
|
}
|
|
158
158
|
}),
|
|
159
159
|
...import_constants.isWeb && {
|
|
160
|
-
onKeyDown: (0, import_helpers.composeEventHandlers)(
|
|
161
|
-
if (
|
|
160
|
+
onKeyDown: (0, import_helpers.composeEventHandlers)(function(event) {
|
|
161
|
+
if ("key" in event) onKeyDown === null || onKeyDown === void 0 || onKeyDown(event);
|
|
162
|
+
}, function(event) {
|
|
163
|
+
var { key } = event.nativeEvent;
|
|
164
|
+
if (key === "Enter" || key === " ") {
|
|
162
165
|
if (!checked) onChange === null || onChange === void 0 || onChange(value);
|
|
163
166
|
}
|
|
164
167
|
}),
|
|
165
|
-
onFocus: (0, import_helpers.composeEventHandlers)(
|
|
168
|
+
onFocus: (0, import_helpers.composeEventHandlers)(function(event) {
|
|
169
|
+
if ("relatedTarget" in event) onFocus === null || onFocus === void 0 || onFocus(event);
|
|
170
|
+
}, function() {
|
|
166
171
|
if (isArrowKeyPressedRef.current) {
|
|
167
172
|
var _ref_current;
|
|
168
173
|
(_ref_current = ref.current) === null || _ref_current === void 0 || _ref_current.click();
|
|
@@ -157,12 +157,17 @@ var useRadioGroupItem = function(params) {
|
|
|
157
157
|
}
|
|
158
158
|
}),
|
|
159
159
|
...import_constants.isWeb && {
|
|
160
|
-
onKeyDown: (0, import_helpers.composeEventHandlers)(
|
|
161
|
-
if (
|
|
160
|
+
onKeyDown: (0, import_helpers.composeEventHandlers)(function(event) {
|
|
161
|
+
if ("key" in event) onKeyDown === null || onKeyDown === void 0 || onKeyDown(event);
|
|
162
|
+
}, function(event) {
|
|
163
|
+
var { key } = event.nativeEvent;
|
|
164
|
+
if (key === "Enter" || key === " ") {
|
|
162
165
|
if (!checked) onChange === null || onChange === void 0 || onChange(value);
|
|
163
166
|
}
|
|
164
167
|
}),
|
|
165
|
-
onFocus: (0, import_helpers.composeEventHandlers)(
|
|
168
|
+
onFocus: (0, import_helpers.composeEventHandlers)(function(event) {
|
|
169
|
+
if ("relatedTarget" in event) onFocus === null || onFocus === void 0 || onFocus(event);
|
|
170
|
+
}, function() {
|
|
166
171
|
if (isArrowKeyPressedRef.current) {
|
|
167
172
|
var _ref_current;
|
|
168
173
|
(_ref_current = ref.current) === null || _ref_current === void 0 || _ref_current.click();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRadioGroup.native.js","names":[],"sources":["cjs/useRadioGroup.native.js"],"sourcesContent":["\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n\tfor (var name in all) __defProp(target, name, {\n\t\tget: all[name],\n\t\tenumerable: true\n\t});\n};\nvar __copyProps = (to, from, except, desc) => {\n\tif (from && typeof from === \"object\" || typeof from === \"function\") {\n\t\tfor (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {\n\t\t\tget: () => from[key],\n\t\t\tenumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable\n\t\t});\n\t}\n\treturn to;\n};\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar useRadioGroup_exports = {};\n__export(useRadioGroup_exports, {\n\tuseRadioGroup: () => useRadioGroup,\n\tuseRadioGroupItem: () => useRadioGroupItem,\n\tuseRadioGroupItemIndicator: () => useRadioGroupItemIndicator\n});\nmodule.exports = __toCommonJS(useRadioGroup_exports);\nvar import_jsx_runtime = require(\"react/jsx-runtime\");\nvar import_compose_refs = require(\"@tamagui/compose-refs\");\nvar import_constants = require(\"@tamagui/constants\");\nvar import_focusable = require(\"@tamagui/focusable\");\nvar import_helpers = require(\"@tamagui/helpers\");\nvar import_label = require(\"@tamagui/label\");\nvar import_use_controllable_state = require(\"@tamagui/use-controllable-state\");\nvar import_react = require(\"react\");\nvar import_BubbleInput = require(\"./BubbleInput\");\nvar import_utils = require(\"./utils\");\nfunction useRadioGroup(params) {\n\tvar { value: valueProp, onValueChange, defaultValue, required, disabled, name, native, accentColor, orientation, ref } = params;\n\tvar [value, setValue] = (0, import_use_controllable_state.useControllableState)({\n\t\tprop: valueProp,\n\t\tdefaultProp: defaultValue,\n\t\tonChange: onValueChange\n\t});\n\treturn {\n\t\tproviderValue: {\n\t\t\tvalue,\n\t\t\tonChange: setValue,\n\t\t\trequired,\n\t\t\tdisabled,\n\t\t\tname,\n\t\t\tnative,\n\t\t\taccentColor\n\t\t},\n\t\tframeAttrs: {\n\t\t\trole: \"radiogroup\",\n\t\t\t\"aria-orientation\": orientation,\n\t\t\t\"data-disabled\": disabled ? \"\" : void 0\n\t\t},\n\t\trovingFocusGroupAttrs: {\n\t\t\torientation,\n\t\t\tloop: true\n\t\t}\n\t};\n}\nvar ARROW_KEYS = [\n\t\"ArrowUp\",\n\t\"ArrowDown\",\n\t\"ArrowLeft\",\n\t\"ArrowRight\"\n];\nvar useRadioGroupItem = function(params) {\n\tvar { radioGroupContext, value, labelledBy: ariaLabelledby, disabled: itemDisabled, ref: refProp, id, onPress, onKeyDown, onFocus } = params;\n\tvar { value: groupValue, disabled, required, onChange, name, native, accentColor } = (0, import_react.useContext)(radioGroupContext);\n\tvar [button, setButton] = (0, import_react.useState)(null);\n\tvar hasConsumerStoppedPropagationRef = (0, import_react.useRef)(false);\n\tvar ref = (0, import_react.useRef)(null);\n\tvar composedRefs = (0, import_compose_refs.useComposedRefs)(refProp, function(node) {\n\t\treturn setButton(node);\n\t}, ref);\n\tvar isArrowKeyPressedRef = (0, import_react.useRef)(false);\n\tvar isFormControl = import_constants.isWeb ? button ? Boolean(button.closest(\"form\")) : true : false;\n\tvar checked = groupValue === value;\n\tvar labelId = (0, import_label.useLabelContext)(button);\n\tvar labelledBy = ariaLabelledby || labelId;\n\t(0, import_react.useEffect)(function() {\n\t\tif (import_constants.isWeb) {\n\t\t\tvar handleKeyDown = function(event) {\n\t\t\t\tif (ARROW_KEYS.includes(event.key)) isArrowKeyPressedRef.current = true;\n\t\t\t};\n\t\t\tvar handleKeyUp = function() {\n\t\t\t\tisArrowKeyPressedRef.current = false;\n\t\t\t};\n\t\t\tdocument.addEventListener(\"keydown\", handleKeyDown);\n\t\t\tdocument.addEventListener(\"keyup\", handleKeyUp);\n\t\t\treturn function() {\n\t\t\t\tdocument.removeEventListener(\"keydown\", handleKeyDown);\n\t\t\t\tdocument.removeEventListener(\"keyup\", handleKeyUp);\n\t\t\t};\n\t\t}\n\t}, []);\n\t(0, import_react.useEffect)(function() {\n\t\tif (!id) return;\n\t\tif (disabled) return;\n\t\treturn (0, import_focusable.registerFocusable)(id, {\n\t\t\tfocusAndSelect: function() {\n\t\t\t\tonChange === null || onChange === void 0 || onChange(value);\n\t\t\t},\n\t\t\tfocus: function() {}\n\t\t});\n\t}, [\n\t\tid,\n\t\tvalue,\n\t\tdisabled\n\t]);\n\tvar isDisabled = disabled || itemDisabled;\n\treturn {\n\t\tproviderValue: { checked },\n\t\tchecked,\n\t\tisFormControl,\n\t\tbubbleInput: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_BubbleInput.BubbleInput, {\n\t\t\tisHidden: !native,\n\t\t\tcontrol: button,\n\t\t\tbubbles: !hasConsumerStoppedPropagationRef.current,\n\t\t\tname,\n\t\t\tvalue,\n\t\t\tchecked,\n\t\t\trequired,\n\t\t\tdisabled: isDisabled,\n\t\t\t...import_constants.isWeb && native && {\n\t\t\t\taccentColor,\n\t\t\t\tid\n\t\t\t}\n\t\t}),\n\t\tnative,\n\t\tframeAttrs: {\n\t\t\t\"data-state\": (0, import_utils.getState)(checked),\n\t\t\t\"data-disabled\": isDisabled ? \"\" : void 0,\n\t\t\trole: \"radio\",\n\t\t\t\"aria-labelledby\": labelledBy,\n\t\t\t\"aria-checked\": checked,\n\t\t\t\"aria-required\": required,\n\t\t\tdisabled: isDisabled,\n\t\t\tref: composedRefs,\n\t\t\t...import_constants.isWeb && {\n\t\t\t\ttype: \"button\",\n\t\t\t\tvalue\n\t\t\t},\n\t\t\tid,\n\t\t\tonPress: (0, import_helpers.composeEventHandlers)(onPress, function(event) {\n\t\t\t\tif (!checked) onChange === null || onChange === void 0 || onChange(value);\n\t\t\t\tif (isFormControl) {\n\t\t\t\t\thasConsumerStoppedPropagationRef.current = event.isPropagationStopped();\n\t\t\t\t\tif (!hasConsumerStoppedPropagationRef.current) event.stopPropagation();\n\t\t\t\t}\n\t\t\t}),\n\t\t\t...import_constants.isWeb && {\n\t\t\t\tonKeyDown: (0, import_helpers.composeEventHandlers)(onKeyDown, function(event) {\n\t\t\t\t\tif (event.key === \"Enter\" || event.key === \" \") {\n\t\t\t\t\t\tif (!checked) onChange === null || onChange === void 0 || onChange(value);\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t\tonFocus: (0, import_helpers.composeEventHandlers)(onFocus, function() {\n\t\t\t\t\tif (isArrowKeyPressedRef.current) {\n\t\t\t\t\t\tvar _ref_current;\n\t\t\t\t\t\t(_ref_current = ref.current) === null || _ref_current === void 0 || _ref_current.click();\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t}\n\t\t},\n\t\trovingFocusGroupAttrs: {\n\t\t\tasChild: \"except-style\",\n\t\t\ttabIndex: isDisabled ? -1 : 0,\n\t\t\tactive: checked\n\t\t}\n\t};\n};\nfunction useRadioGroupItemIndicator(params) {\n\tvar { radioGroupItemContext, disabled, ...rest } = params;\n\tvar { checked } = (0, import_react.useContext)(radioGroupItemContext);\n\treturn {\n\t\tchecked,\n\t\t\"data-state\": (0, import_utils.getState)(checked),\n\t\t\"data-disabled\": disabled ? \"\" : void 0,\n\t\t...rest\n\t};\n}\n//# sourceMappingURL=useRadioGroup.js.map\n"],"mappings":";;;AACA,IAAI,YAAY,OAAO;AACvB,IAAI,mBAAmB,OAAO;AAC9B,IAAI,oBAAoB,OAAO;AAC/B,IAAI,e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e,qBAAoB,CAAE,WAAW,SAAS,OAAO;KAC9E,IAAI,MAAM,QAAQ,WAAW,MAAM,QAAQ,KAAK;MAC/C,IAAI,CAAC,SAAS,aAAa,QAAQ,aAAa,KAAK,KAAK,SAAS,KAAK;KACzE;IACD,CAAC;IACD,UAAU,GAAG,eAAe,qBAAoB,CAAE,SAAS,WAAW;KACrE,IAAI,qBAAqB,SAAS;MACjC,IAAI;MACJ,CAAC,eAAe,IAAI,aAAa,QAAQ,iBAAiB,KAAK,KAAK,aAAa,MAAM;KACxF;IACD,CAAC;GACF;EACD;EACA,uBAAuB;GACtB,SAAS;GACT,UAAU,aAAa,CAAC,IAAI;GAC5B,QAAQ;EACT;CACD;AACD;AACA,SAAS,2BAA2B,QAAQ;CAC3C,IAAI,EAAE,uBAAuB,UAAU,GAAG,SAAS;CACnD,IAAI,EAAE,aAAa,GAAG,aAAa,WAAU,CAAE,qBAAqB;CACpE,OAAO;EACN;EACA,eAAe,GAAG,aAAa,SAAQ,CAAE,OAAO;EAChD,iBAAiB,WAAW,KAAK,KAAK;EACtC,GAAG;CACJ;AACD"}
|
|
1
|
+
{"version":3,"file":"useRadioGroup.native.js","names":[],"sources":["cjs/useRadioGroup.native.js"],"sourcesContent":["\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n\tfor (var name in all) __defProp(target, name, {\n\t\tget: all[name],\n\t\tenumerable: true\n\t});\n};\nvar __copyProps = (to, from, except, desc) => {\n\tif (from && typeof from === \"object\" || typeof from === \"function\") {\n\t\tfor (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {\n\t\t\tget: () => from[key],\n\t\t\tenumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable\n\t\t});\n\t}\n\treturn to;\n};\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar useRadioGroup_exports = {};\n__export(useRadioGroup_exports, {\n\tuseRadioGroup: () => useRadioGroup,\n\tuseRadioGroupItem: () => useRadioGroupItem,\n\tuseRadioGroupItemIndicator: () => useRadioGroupItemIndicator\n});\nmodule.exports = __toCommonJS(useRadioGroup_exports);\nvar import_jsx_runtime = require(\"react/jsx-runtime\");\nvar import_compose_refs = require(\"@tamagui/compose-refs\");\nvar import_constants = require(\"@tamagui/constants\");\nvar import_focusable = require(\"@tamagui/focusable\");\nvar import_helpers = require(\"@tamagui/helpers\");\nvar import_label = require(\"@tamagui/label\");\nvar import_use_controllable_state = require(\"@tamagui/use-controllable-state\");\nvar import_react = require(\"react\");\nvar import_BubbleInput = require(\"./BubbleInput\");\nvar import_utils = require(\"./utils\");\nfunction useRadioGroup(params) {\n\tvar { value: valueProp, onValueChange, defaultValue, required, disabled, name, native, accentColor, orientation, ref } = params;\n\tvar [value, setValue] = (0, import_use_controllable_state.useControllableState)({\n\t\tprop: valueProp,\n\t\tdefaultProp: defaultValue,\n\t\tonChange: onValueChange\n\t});\n\treturn {\n\t\tproviderValue: {\n\t\t\tvalue,\n\t\t\tonChange: setValue,\n\t\t\trequired,\n\t\t\tdisabled,\n\t\t\tname,\n\t\t\tnative,\n\t\t\taccentColor\n\t\t},\n\t\tframeAttrs: {\n\t\t\trole: \"radiogroup\",\n\t\t\t\"aria-orientation\": orientation,\n\t\t\t\"data-disabled\": disabled ? \"\" : void 0\n\t\t},\n\t\trovingFocusGroupAttrs: {\n\t\t\torientation,\n\t\t\tloop: true\n\t\t}\n\t};\n}\nvar ARROW_KEYS = [\n\t\"ArrowUp\",\n\t\"ArrowDown\",\n\t\"ArrowLeft\",\n\t\"ArrowRight\"\n];\nvar useRadioGroupItem = function(params) {\n\tvar { radioGroupContext, value, labelledBy: ariaLabelledby, disabled: itemDisabled, ref: refProp, id, onPress, onKeyDown, onFocus } = params;\n\tvar { value: groupValue, disabled, required, onChange, name, native, accentColor } = (0, import_react.useContext)(radioGroupContext);\n\tvar [button, setButton] = (0, import_react.useState)(null);\n\tvar hasConsumerStoppedPropagationRef = (0, import_react.useRef)(false);\n\tvar ref = (0, import_react.useRef)(null);\n\tvar composedRefs = (0, import_compose_refs.useComposedRefs)(refProp, function(node) {\n\t\treturn setButton(node);\n\t}, ref);\n\tvar isArrowKeyPressedRef = (0, import_react.useRef)(false);\n\tvar isFormControl = import_constants.isWeb ? button ? Boolean(button.closest(\"form\")) : true : false;\n\tvar checked = groupValue === value;\n\tvar labelId = (0, import_label.useLabelContext)(button);\n\tvar labelledBy = ariaLabelledby || labelId;\n\t(0, import_react.useEffect)(function() {\n\t\tif (import_constants.isWeb) {\n\t\t\tvar handleKeyDown = function(event) {\n\t\t\t\tif (ARROW_KEYS.includes(event.key)) isArrowKeyPressedRef.current = true;\n\t\t\t};\n\t\t\tvar handleKeyUp = function() {\n\t\t\t\tisArrowKeyPressedRef.current = false;\n\t\t\t};\n\t\t\tdocument.addEventListener(\"keydown\", handleKeyDown);\n\t\t\tdocument.addEventListener(\"keyup\", handleKeyUp);\n\t\t\treturn function() {\n\t\t\t\tdocument.removeEventListener(\"keydown\", handleKeyDown);\n\t\t\t\tdocument.removeEventListener(\"keyup\", handleKeyUp);\n\t\t\t};\n\t\t}\n\t}, []);\n\t(0, import_react.useEffect)(function() {\n\t\tif (!id) return;\n\t\tif (disabled) return;\n\t\treturn (0, import_focusable.registerFocusable)(id, {\n\t\t\tfocusAndSelect: function() {\n\t\t\t\tonChange === null || onChange === void 0 || onChange(value);\n\t\t\t},\n\t\t\tfocus: function() {}\n\t\t});\n\t}, [\n\t\tid,\n\t\tvalue,\n\t\tdisabled\n\t]);\n\tvar isDisabled = disabled || itemDisabled;\n\treturn {\n\t\tproviderValue: { checked },\n\t\tchecked,\n\t\tisFormControl,\n\t\tbubbleInput: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_BubbleInput.BubbleInput, {\n\t\t\tisHidden: !native,\n\t\t\tcontrol: button,\n\t\t\tbubbles: !hasConsumerStoppedPropagationRef.current,\n\t\t\tname,\n\t\t\tvalue,\n\t\t\tchecked,\n\t\t\trequired,\n\t\t\tdisabled: isDisabled,\n\t\t\t...import_constants.isWeb && native && {\n\t\t\t\taccentColor,\n\t\t\t\tid\n\t\t\t}\n\t\t}),\n\t\tnative,\n\t\tframeAttrs: {\n\t\t\t\"data-state\": (0, import_utils.getState)(checked),\n\t\t\t\"data-disabled\": isDisabled ? \"\" : void 0,\n\t\t\trole: \"radio\",\n\t\t\t\"aria-labelledby\": labelledBy,\n\t\t\t\"aria-checked\": checked,\n\t\t\t\"aria-required\": required,\n\t\t\tdisabled: isDisabled,\n\t\t\tref: composedRefs,\n\t\t\t...import_constants.isWeb && {\n\t\t\t\ttype: \"button\",\n\t\t\t\tvalue\n\t\t\t},\n\t\t\tid,\n\t\t\tonPress: (0, import_helpers.composeEventHandlers)(onPress, function(event) {\n\t\t\t\tif (!checked) onChange === null || onChange === void 0 || onChange(value);\n\t\t\t\tif (isFormControl) {\n\t\t\t\t\thasConsumerStoppedPropagationRef.current = event.isPropagationStopped();\n\t\t\t\t\tif (!hasConsumerStoppedPropagationRef.current) event.stopPropagation();\n\t\t\t\t}\n\t\t\t}),\n\t\t\t...import_constants.isWeb && {\n\t\t\t\tonKeyDown: (0, import_helpers.composeEventHandlers)(function(event) {\n\t\t\t\t\tif (\"key\" in event) onKeyDown === null || onKeyDown === void 0 || onKeyDown(event);\n\t\t\t\t}, function(event) {\n\t\t\t\t\tvar { key } = event.nativeEvent;\n\t\t\t\t\tif (key === \"Enter\" || key === \" \") {\n\t\t\t\t\t\tif (!checked) onChange === null || onChange === void 0 || onChange(value);\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t\tonFocus: (0, import_helpers.composeEventHandlers)(function(event) {\n\t\t\t\t\tif (\"relatedTarget\" in event) onFocus === null || onFocus === void 0 || onFocus(event);\n\t\t\t\t}, function() {\n\t\t\t\t\tif (isArrowKeyPressedRef.current) {\n\t\t\t\t\t\tvar _ref_current;\n\t\t\t\t\t\t(_ref_current = ref.current) === null || _ref_current === void 0 || _ref_current.click();\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t}\n\t\t},\n\t\trovingFocusGroupAttrs: {\n\t\t\tasChild: \"except-style\",\n\t\t\ttabIndex: isDisabled ? -1 : 0,\n\t\t\tactive: checked\n\t\t}\n\t};\n};\nfunction useRadioGroupItemIndicator(params) {\n\tvar { radioGroupItemContext, disabled, ...rest } = params;\n\tvar { checked } = (0, import_react.useContext)(radioGroupItemContext);\n\treturn {\n\t\tchecked,\n\t\t\"data-state\": (0, import_utils.getState)(checked),\n\t\t\"data-disabled\": disabled ? \"\" : void 0,\n\t\t...rest\n\t};\n}\n//# sourceMappingURL=useRadioGroup.js.map\n"],"mappings":";;;AACA,IAAI,YAAY,OAAO;AACvB,IAAI,mBAAmB,OAAO;AAC9B,IAAI,oBAAoB,OAAO;AAC/B,IAAI,eAAe,OAAO,UAAU;AACpC,IAAI,YAAY,QAAQ,QAAQ;CAC/B,KAAK,IAAI,QAAQ,KAAK,UAAU,QAAQ,MAAM;EAC7C,KAAK,IAAI;EACT,YAAY;CACb,CAAC;AACF;AACA,IAAI,eAAe,IAAI,MAAM,QAAQ,SAAS;CAC7C,IAAI,QAAQ,OAAO,SAAS,YAAY,OAAO,SAAS,YAAY;EACnE,KAAK,IAAI,OAAO,kBAAkB,IAAI,GAAG,IAAI,CAAC,aAAa,KAAK,IAAI,GAAG,KAAK,QAAQ,QAAQ,UAAU,IAAI,KAAK;GAC9G,WAAW,KAAK;GAChB,YAAY,EAAE,OAAO,iBAAiB,MAAM,GAAG,MAAM,KAAK;EAC3D,CAAC;CACF;CACA,OAAO;AACR;AACA,IAAI,gBAAgB,QAAQ,YAAY,UAAU,CAAC,GAAG,cAAc,EAAE,OAAO,KAAK,CAAC,GAAG,GAAG;AACzF,IAAI,wBAAwB,CAAC;AAC7B,SAAS,uBAAuB;CAC/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CACD;AACD;AACA,SAAS,2BAA2B,QAAQ;CAC3C,IAAI,EAAE,uBAAuB,UAAU,GAAG,SAAS;CACnD,IAAI,EAAE,aAAa,GAAG,aAAa,WAAU,CAAE,qBAAqB;CACpE,OAAO;EACN;EACA,eAAe,GAAG,aAAa,SAAQ,CAAE,OAAO;EAChD,iBAAiB,WAAW,KAAK,KAAK;EACtC,GAAG;CACJ;AACD"}
|
|
@@ -112,12 +112,17 @@ const useRadioGroupItem = (params) => {
|
|
|
112
112
|
}
|
|
113
113
|
}),
|
|
114
114
|
...isWeb && {
|
|
115
|
-
onKeyDown: composeEventHandlers(
|
|
116
|
-
if (
|
|
115
|
+
onKeyDown: composeEventHandlers((event) => {
|
|
116
|
+
if ("key" in event) onKeyDown?.(event);
|
|
117
|
+
}, (event) => {
|
|
118
|
+
const { key } = event.nativeEvent;
|
|
119
|
+
if (key === "Enter" || key === " ") {
|
|
117
120
|
if (!checked) onChange?.(value);
|
|
118
121
|
}
|
|
119
122
|
}),
|
|
120
|
-
onFocus: composeEventHandlers(
|
|
123
|
+
onFocus: composeEventHandlers((event) => {
|
|
124
|
+
if ("relatedTarget" in event) onFocus?.(event);
|
|
125
|
+
}, () => {
|
|
121
126
|
if (isArrowKeyPressedRef.current) ref.current?.click();
|
|
122
127
|
})
|
|
123
128
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRadioGroup.js","names":[],"sources":["esm/useRadioGroup.js"],"sourcesContent":["import { useComposedRefs } from \"@tamagui/compose-refs\";\nimport { isWeb } from \"@tamagui/constants\";\nimport { composeEventHandlers } from \"@tamagui/helpers\";\nimport { useLabelContext } from \"@tamagui/label\";\nimport { useControllableState } from \"@tamagui/use-controllable-state\";\nimport { useContext, useEffect, useRef, useState } from \"react\";\nimport { BubbleInput } from \"./BubbleInput\";\nimport { getState } from \"./utils\";\nimport { jsx } from \"react/jsx-runtime\";\n\nfunction useRadioGroup(params) {\n\tconst { value: valueProp, onValueChange, defaultValue, required, disabled, name, native, accentColor, orientation, ref } = params;\n\tconst [value, setValue] = useControllableState({\n\t\tprop: valueProp,\n\t\tdefaultProp: defaultValue,\n\t\tonChange: onValueChange\n\t});\n\treturn {\n\t\tproviderValue: {\n\t\t\tvalue,\n\t\t\tonChange: setValue,\n\t\t\trequired,\n\t\t\tdisabled,\n\t\t\tname,\n\t\t\tnative,\n\t\t\taccentColor\n\t\t},\n\t\tframeAttrs: {\n\t\t\trole: \"radiogroup\",\n\t\t\t\"aria-orientation\": orientation,\n\t\t\t\"data-disabled\": disabled ? \"\" : void 0\n\t\t},\n\t\trovingFocusGroupAttrs: {\n\t\t\torientation,\n\t\t\tloop: true\n\t\t}\n\t};\n}\nconst ARROW_KEYS = [\n\t\"ArrowUp\",\n\t\"ArrowDown\",\n\t\"ArrowLeft\",\n\t\"ArrowRight\"\n];\nconst useRadioGroupItem = (params) => {\n\tconst { radioGroupContext, value, labelledBy: ariaLabelledby, disabled: itemDisabled, ref: refProp, id, onPress, onKeyDown, onFocus } = params;\n\tconst { value: groupValue, disabled, required, onChange, name, native, accentColor } = useContext(radioGroupContext);\n\tconst [button, setButton] = useState(null);\n\tconst hasConsumerStoppedPropagationRef = useRef(false);\n\tconst ref = useRef(null);\n\tconst composedRefs = useComposedRefs(refProp, (node) => setButton(node), ref);\n\tconst isArrowKeyPressedRef = useRef(false);\n\tconst isFormControl = isWeb ? button ? Boolean(button.closest(\"form\")) : true : false;\n\tconst checked = groupValue === value;\n\tconst labelId = useLabelContext(button);\n\tconst labelledBy = ariaLabelledby || labelId;\n\tuseEffect(() => {\n\t\tif (isWeb) {\n\t\t\tconst handleKeyDown = (event) => {\n\t\t\t\tif (ARROW_KEYS.includes(event.key)) isArrowKeyPressedRef.current = true;\n\t\t\t};\n\t\t\tconst handleKeyUp = () => {\n\t\t\t\tisArrowKeyPressedRef.current = false;\n\t\t\t};\n\t\t\tdocument.addEventListener(\"keydown\", handleKeyDown);\n\t\t\tdocument.addEventListener(\"keyup\", handleKeyUp);\n\t\t\treturn () => {\n\t\t\t\tdocument.removeEventListener(\"keydown\", handleKeyDown);\n\t\t\t\tdocument.removeEventListener(\"keyup\", handleKeyUp);\n\t\t\t};\n\t\t}\n\t}, []);\n\tconst isDisabled = disabled || itemDisabled;\n\treturn {\n\t\tproviderValue: { checked },\n\t\tchecked,\n\t\tisFormControl,\n\t\tbubbleInput: /* @__PURE__ */ jsx(BubbleInput, {\n\t\t\tisHidden: !native,\n\t\t\tcontrol: button,\n\t\t\tbubbles: !hasConsumerStoppedPropagationRef.current,\n\t\t\tname,\n\t\t\tvalue,\n\t\t\tchecked,\n\t\t\trequired,\n\t\t\tdisabled: isDisabled,\n\t\t\t...isWeb && native && {\n\t\t\t\taccentColor,\n\t\t\t\tid\n\t\t\t}\n\t\t}),\n\t\tnative,\n\t\tframeAttrs: {\n\t\t\t\"data-state\": getState(checked),\n\t\t\t\"data-disabled\": isDisabled ? \"\" : void 0,\n\t\t\trole: \"radio\",\n\t\t\t\"aria-labelledby\": labelledBy,\n\t\t\t\"aria-checked\": checked,\n\t\t\t\"aria-required\": required,\n\t\t\tdisabled: isDisabled,\n\t\t\tref: composedRefs,\n\t\t\t...isWeb && {\n\t\t\t\ttype: \"button\",\n\t\t\t\tvalue\n\t\t\t},\n\t\t\tid,\n\t\t\tonPress: composeEventHandlers(onPress, (event) => {\n\t\t\t\tif (!checked) onChange?.(value);\n\t\t\t\tif (isFormControl) {\n\t\t\t\t\thasConsumerStoppedPropagationRef.current = event.isPropagationStopped();\n\t\t\t\t\tif (!hasConsumerStoppedPropagationRef.current) event.stopPropagation();\n\t\t\t\t}\n\t\t\t}),\n\t\t\t...isWeb && {\n\t\t\t\tonKeyDown: composeEventHandlers(onKeyDown, (event) => {\n\t\t\t\t\tif (
|
|
1
|
+
{"version":3,"file":"useRadioGroup.js","names":[],"sources":["esm/useRadioGroup.js"],"sourcesContent":["import { useComposedRefs } from \"@tamagui/compose-refs\";\nimport { isWeb } from \"@tamagui/constants\";\nimport { composeEventHandlers } from \"@tamagui/helpers\";\nimport { useLabelContext } from \"@tamagui/label\";\nimport { useControllableState } from \"@tamagui/use-controllable-state\";\nimport { useContext, useEffect, useRef, useState } from \"react\";\nimport { BubbleInput } from \"./BubbleInput\";\nimport { getState } from \"./utils\";\nimport { jsx } from \"react/jsx-runtime\";\n\nfunction useRadioGroup(params) {\n\tconst { value: valueProp, onValueChange, defaultValue, required, disabled, name, native, accentColor, orientation, ref } = params;\n\tconst [value, setValue] = useControllableState({\n\t\tprop: valueProp,\n\t\tdefaultProp: defaultValue,\n\t\tonChange: onValueChange\n\t});\n\treturn {\n\t\tproviderValue: {\n\t\t\tvalue,\n\t\t\tonChange: setValue,\n\t\t\trequired,\n\t\t\tdisabled,\n\t\t\tname,\n\t\t\tnative,\n\t\t\taccentColor\n\t\t},\n\t\tframeAttrs: {\n\t\t\trole: \"radiogroup\",\n\t\t\t\"aria-orientation\": orientation,\n\t\t\t\"data-disabled\": disabled ? \"\" : void 0\n\t\t},\n\t\trovingFocusGroupAttrs: {\n\t\t\torientation,\n\t\t\tloop: true\n\t\t}\n\t};\n}\nconst ARROW_KEYS = [\n\t\"ArrowUp\",\n\t\"ArrowDown\",\n\t\"ArrowLeft\",\n\t\"ArrowRight\"\n];\nconst useRadioGroupItem = (params) => {\n\tconst { radioGroupContext, value, labelledBy: ariaLabelledby, disabled: itemDisabled, ref: refProp, id, onPress, onKeyDown, onFocus } = params;\n\tconst { value: groupValue, disabled, required, onChange, name, native, accentColor } = useContext(radioGroupContext);\n\tconst [button, setButton] = useState(null);\n\tconst hasConsumerStoppedPropagationRef = useRef(false);\n\tconst ref = useRef(null);\n\tconst composedRefs = useComposedRefs(refProp, (node) => setButton(node), ref);\n\tconst isArrowKeyPressedRef = useRef(false);\n\tconst isFormControl = isWeb ? button ? Boolean(button.closest(\"form\")) : true : false;\n\tconst checked = groupValue === value;\n\tconst labelId = useLabelContext(button);\n\tconst labelledBy = ariaLabelledby || labelId;\n\tuseEffect(() => {\n\t\tif (isWeb) {\n\t\t\tconst handleKeyDown = (event) => {\n\t\t\t\tif (ARROW_KEYS.includes(event.key)) isArrowKeyPressedRef.current = true;\n\t\t\t};\n\t\t\tconst handleKeyUp = () => {\n\t\t\t\tisArrowKeyPressedRef.current = false;\n\t\t\t};\n\t\t\tdocument.addEventListener(\"keydown\", handleKeyDown);\n\t\t\tdocument.addEventListener(\"keyup\", handleKeyUp);\n\t\t\treturn () => {\n\t\t\t\tdocument.removeEventListener(\"keydown\", handleKeyDown);\n\t\t\t\tdocument.removeEventListener(\"keyup\", handleKeyUp);\n\t\t\t};\n\t\t}\n\t}, []);\n\tconst isDisabled = disabled || itemDisabled;\n\treturn {\n\t\tproviderValue: { checked },\n\t\tchecked,\n\t\tisFormControl,\n\t\tbubbleInput: /* @__PURE__ */ jsx(BubbleInput, {\n\t\t\tisHidden: !native,\n\t\t\tcontrol: button,\n\t\t\tbubbles: !hasConsumerStoppedPropagationRef.current,\n\t\t\tname,\n\t\t\tvalue,\n\t\t\tchecked,\n\t\t\trequired,\n\t\t\tdisabled: isDisabled,\n\t\t\t...isWeb && native && {\n\t\t\t\taccentColor,\n\t\t\t\tid\n\t\t\t}\n\t\t}),\n\t\tnative,\n\t\tframeAttrs: {\n\t\t\t\"data-state\": getState(checked),\n\t\t\t\"data-disabled\": isDisabled ? \"\" : void 0,\n\t\t\trole: \"radio\",\n\t\t\t\"aria-labelledby\": labelledBy,\n\t\t\t\"aria-checked\": checked,\n\t\t\t\"aria-required\": required,\n\t\t\tdisabled: isDisabled,\n\t\t\tref: composedRefs,\n\t\t\t...isWeb && {\n\t\t\t\ttype: \"button\",\n\t\t\t\tvalue\n\t\t\t},\n\t\t\tid,\n\t\t\tonPress: composeEventHandlers(onPress, (event) => {\n\t\t\t\tif (!checked) onChange?.(value);\n\t\t\t\tif (isFormControl) {\n\t\t\t\t\thasConsumerStoppedPropagationRef.current = event.isPropagationStopped();\n\t\t\t\t\tif (!hasConsumerStoppedPropagationRef.current) event.stopPropagation();\n\t\t\t\t}\n\t\t\t}),\n\t\t\t...isWeb && {\n\t\t\t\tonKeyDown: composeEventHandlers((event) => {\n\t\t\t\t\tif (\"key\" in event) onKeyDown?.(event);\n\t\t\t\t}, (event) => {\n\t\t\t\t\tconst { key } = event.nativeEvent;\n\t\t\t\t\tif (key === \"Enter\" || key === \" \") {\n\t\t\t\t\t\tif (!checked) onChange?.(value);\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t\tonFocus: composeEventHandlers((event) => {\n\t\t\t\t\tif (\"relatedTarget\" in event) onFocus?.(event);\n\t\t\t\t}, () => {\n\t\t\t\t\tif (isArrowKeyPressedRef.current) ref.current?.click();\n\t\t\t\t})\n\t\t\t}\n\t\t},\n\t\trovingFocusGroupAttrs: {\n\t\t\tasChild: \"except-style\",\n\t\t\ttabIndex: isDisabled ? -1 : 0,\n\t\t\tactive: checked\n\t\t}\n\t};\n};\nfunction useRadioGroupItemIndicator(params) {\n\tconst { radioGroupItemContext, disabled, ...rest } = params;\n\tconst { checked } = useContext(radioGroupItemContext);\n\treturn {\n\t\tchecked,\n\t\t\"data-state\": getState(checked),\n\t\t\"data-disabled\": disabled ? \"\" : void 0,\n\t\t...rest\n\t};\n}\n\nexport { useRadioGroup, useRadioGroupItem, useRadioGroupItemIndicator };"],"mappings":";;;;;;;;;;;AAUA,SAAS,cAAc,QAAQ;CAC9B,MAAM,EAAE,OAAO,WAAW,eAAe,cAAc,UAAU,UAAU,MAAM,QAAQ,aAAa,aAAa,QAAQ;CAC3H,MAAM,CAAC,OAAO,YAAY,qBAAqB;EAC9C,MAAM;EACN,aAAa;EACb,UAAU;CACX,CAAC;CACD,OAAO;EACN,eAAe;GACd;GACA,UAAU;GACV;GACA;GACA;GACA;GACA;EACD;EACA,YAAY;GACX,MAAM;GACN,oBAAoB;GACpB,iBAAiB,WAAW,KAAK,KAAK;EACvC;EACA,uBAAuB;GACtB;GACA,MAAM;EACP;CACD;AACD;AACA,MAAM,aAAa;CAClB;CACA;CACA;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AAM;GACN,mBAAmB;GACnB,gBAAgB;GAChB,iBAAiB;GACjB,UAAU;GACV,KAAK;GACL,GAAG,SAAS;IACX,MAAM;IACN;GACD;GACA;GACA,SAAS,qBAAqB,UAAU,UAAU;IACjD,IAAI,CAAC,SAAS,WAAW,KAAK;IAC9B,IAAI,eAAe;KAClB,iCAAiC,UAAU,MAAM,qBAAqB;KACtE,IAAI,CAAC,iCAAiC,SAAS,MAAM,gBAAgB;IACtE;GACD,CAAC;GACD,GAAG,SAAS;IACX,WAAW,sBAAsB,UAAU;KAC1C,IAAI,SAAS,OAAO,YAAY,KAAK;IACtC,IAAI,UAAU;KACb,MAAM,EAAE,QAAQ,MAAM;KACtB,IAAI,QAAQ,WAAW,QAAQ,KAAK;MACnC,IAAI,CAAC,SAAS,WAAW,KAAK;KAC/B;IACD,CAAC;IACD,SAAS,sBAAsB,UAAU;KACxC,IAAI,mBAAmB,OAAO,UAAU,KAAK;IAC9C,SAAS;KACR,IAAI,qBAAqB,SAAS,IAAI,SAAS,MAAM;IACtD,CAAC;GACF;EACD;EACA,uBAAuB;GACtB,SAAS;GACT,UAAU,aAAa,CAAC,IAAI;GAC5B,QAAQ;EACT;CACD;AACD;AACA,SAAS,2BAA2B,QAAQ;CAC3C,MAAM,EAAE,uBAAuB,UAAU,GAAG,SAAS;CACrD,MAAM,EAAE,YAAY,WAAW,qBAAqB;CACpD,OAAO;EACN;EACA,cAAc,SAAS,OAAO;EAC9B,iBAAiB,WAAW,KAAK,KAAK;EACtC,GAAG;CACJ;AACD"}
|
|
@@ -129,12 +129,17 @@ var useRadioGroupItem = function(params) {
|
|
|
129
129
|
}
|
|
130
130
|
}),
|
|
131
131
|
...isWeb && {
|
|
132
|
-
onKeyDown: composeEventHandlers(
|
|
133
|
-
if (
|
|
132
|
+
onKeyDown: composeEventHandlers(function(event) {
|
|
133
|
+
if ("key" in event) onKeyDown === null || onKeyDown === void 0 || onKeyDown(event);
|
|
134
|
+
}, function(event) {
|
|
135
|
+
var { key } = event.nativeEvent;
|
|
136
|
+
if (key === "Enter" || key === " ") {
|
|
134
137
|
if (!checked) onChange === null || onChange === void 0 || onChange(value);
|
|
135
138
|
}
|
|
136
139
|
}),
|
|
137
|
-
onFocus: composeEventHandlers(
|
|
140
|
+
onFocus: composeEventHandlers(function(event) {
|
|
141
|
+
if ("relatedTarget" in event) onFocus === null || onFocus === void 0 || onFocus(event);
|
|
142
|
+
}, function() {
|
|
138
143
|
if (isArrowKeyPressedRef.current) {
|
|
139
144
|
var _ref_current;
|
|
140
145
|
(_ref_current = ref.current) === null || _ref_current === void 0 || _ref_current.click();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRadioGroup.native.js","names":[],"sources":["esm/useRadioGroup.native.js"],"sourcesContent":["import { jsx } from \"react/jsx-runtime\";\nimport { useComposedRefs } from \"@tamagui/compose-refs\";\nimport { isWeb } from \"@tamagui/constants\";\nimport { registerFocusable } from \"@tamagui/focusable\";\nimport { composeEventHandlers } from \"@tamagui/helpers\";\nimport { useLabelContext } from \"@tamagui/label\";\nimport { useControllableState } from \"@tamagui/use-controllable-state\";\nimport { useContext, useEffect, useRef, useState } from \"react\";\nimport { BubbleInput } from \"./BubbleInput\";\nimport { getState } from \"./utils\";\n\nfunction useRadioGroup(params) {\n\tvar { value: valueProp, onValueChange, defaultValue, required, disabled, name, native, accentColor, orientation, ref } = params;\n\tvar [value, setValue] = useControllableState({\n\t\tprop: valueProp,\n\t\tdefaultProp: defaultValue,\n\t\tonChange: onValueChange\n\t});\n\treturn {\n\t\tproviderValue: {\n\t\t\tvalue,\n\t\t\tonChange: setValue,\n\t\t\trequired,\n\t\t\tdisabled,\n\t\t\tname,\n\t\t\tnative,\n\t\t\taccentColor\n\t\t},\n\t\tframeAttrs: {\n\t\t\trole: \"radiogroup\",\n\t\t\t\"aria-orientation\": orientation,\n\t\t\t\"data-disabled\": disabled ? \"\" : void 0\n\t\t},\n\t\trovingFocusGroupAttrs: {\n\t\t\torientation,\n\t\t\tloop: true\n\t\t}\n\t};\n}\nvar ARROW_KEYS = [\n\t\"ArrowUp\",\n\t\"ArrowDown\",\n\t\"ArrowLeft\",\n\t\"ArrowRight\"\n];\nvar useRadioGroupItem = function(params) {\n\tvar { radioGroupContext, value, labelledBy: ariaLabelledby, disabled: itemDisabled, ref: refProp, id, onPress, onKeyDown, onFocus } = params;\n\tvar { value: groupValue, disabled, required, onChange, name, native, accentColor } = useContext(radioGroupContext);\n\tvar [button, setButton] = useState(null);\n\tvar hasConsumerStoppedPropagationRef = useRef(false);\n\tvar ref = useRef(null);\n\tvar composedRefs = useComposedRefs(refProp, function(node) {\n\t\treturn setButton(node);\n\t}, ref);\n\tvar isArrowKeyPressedRef = useRef(false);\n\tvar isFormControl = isWeb ? button ? Boolean(button.closest(\"form\")) : true : false;\n\tvar checked = groupValue === value;\n\tvar labelId = useLabelContext(button);\n\tvar labelledBy = ariaLabelledby || labelId;\n\tuseEffect(function() {\n\t\tif (isWeb) {\n\t\t\tvar handleKeyDown = function(event) {\n\t\t\t\tif (ARROW_KEYS.includes(event.key)) isArrowKeyPressedRef.current = true;\n\t\t\t};\n\t\t\tvar handleKeyUp = function() {\n\t\t\t\tisArrowKeyPressedRef.current = false;\n\t\t\t};\n\t\t\tdocument.addEventListener(\"keydown\", handleKeyDown);\n\t\t\tdocument.addEventListener(\"keyup\", handleKeyUp);\n\t\t\treturn function() {\n\t\t\t\tdocument.removeEventListener(\"keydown\", handleKeyDown);\n\t\t\t\tdocument.removeEventListener(\"keyup\", handleKeyUp);\n\t\t\t};\n\t\t}\n\t}, []);\n\tuseEffect(function() {\n\t\tif (!id) return;\n\t\tif (disabled) return;\n\t\treturn registerFocusable(id, {\n\t\t\tfocusAndSelect: function() {\n\t\t\t\tonChange === null || onChange === void 0 || onChange(value);\n\t\t\t},\n\t\t\tfocus: function() {}\n\t\t});\n\t}, [\n\t\tid,\n\t\tvalue,\n\t\tdisabled\n\t]);\n\tvar isDisabled = disabled || itemDisabled;\n\treturn {\n\t\tproviderValue: { checked },\n\t\tchecked,\n\t\tisFormControl,\n\t\tbubbleInput: /* @__PURE__ */ jsx(BubbleInput, {\n\t\t\tisHidden: !native,\n\t\t\tcontrol: button,\n\t\t\tbubbles: !hasConsumerStoppedPropagationRef.current,\n\t\t\tname,\n\t\t\tvalue,\n\t\t\tchecked,\n\t\t\trequired,\n\t\t\tdisabled: isDisabled,\n\t\t\t...isWeb && native && {\n\t\t\t\taccentColor,\n\t\t\t\tid\n\t\t\t}\n\t\t}),\n\t\tnative,\n\t\tframeAttrs: {\n\t\t\t\"data-state\": getState(checked),\n\t\t\t\"data-disabled\": isDisabled ? \"\" : void 0,\n\t\t\trole: \"radio\",\n\t\t\t\"aria-labelledby\": labelledBy,\n\t\t\t\"aria-checked\": checked,\n\t\t\t\"aria-required\": required,\n\t\t\tdisabled: isDisabled,\n\t\t\tref: composedRefs,\n\t\t\t...isWeb && {\n\t\t\t\ttype: \"button\",\n\t\t\t\tvalue\n\t\t\t},\n\t\t\tid,\n\t\t\tonPress: composeEventHandlers(onPress, function(event) {\n\t\t\t\tif (!checked) onChange === null || onChange === void 0 || onChange(value);\n\t\t\t\tif (isFormControl) {\n\t\t\t\t\thasConsumerStoppedPropagationRef.current = event.isPropagationStopped();\n\t\t\t\t\tif (!hasConsumerStoppedPropagationRef.current) event.stopPropagation();\n\t\t\t\t}\n\t\t\t}),\n\t\t\t...isWeb && {\n\t\t\t\tonKeyDown: composeEventHandlers(onKeyDown, function(event) {\n\t\t\t\t\tif (
|
|
1
|
+
{"version":3,"file":"useRadioGroup.native.js","names":[],"sources":["esm/useRadioGroup.native.js"],"sourcesContent":["import { jsx } from \"react/jsx-runtime\";\nimport { useComposedRefs } from \"@tamagui/compose-refs\";\nimport { isWeb } from \"@tamagui/constants\";\nimport { registerFocusable } from \"@tamagui/focusable\";\nimport { composeEventHandlers } from \"@tamagui/helpers\";\nimport { useLabelContext } from \"@tamagui/label\";\nimport { useControllableState } from \"@tamagui/use-controllable-state\";\nimport { useContext, useEffect, useRef, useState } from \"react\";\nimport { BubbleInput } from \"./BubbleInput\";\nimport { getState } from \"./utils\";\n\nfunction useRadioGroup(params) {\n\tvar { value: valueProp, onValueChange, defaultValue, required, disabled, name, native, accentColor, orientation, ref } = params;\n\tvar [value, setValue] = useControllableState({\n\t\tprop: valueProp,\n\t\tdefaultProp: defaultValue,\n\t\tonChange: onValueChange\n\t});\n\treturn {\n\t\tproviderValue: {\n\t\t\tvalue,\n\t\t\tonChange: setValue,\n\t\t\trequired,\n\t\t\tdisabled,\n\t\t\tname,\n\t\t\tnative,\n\t\t\taccentColor\n\t\t},\n\t\tframeAttrs: {\n\t\t\trole: \"radiogroup\",\n\t\t\t\"aria-orientation\": orientation,\n\t\t\t\"data-disabled\": disabled ? \"\" : void 0\n\t\t},\n\t\trovingFocusGroupAttrs: {\n\t\t\torientation,\n\t\t\tloop: true\n\t\t}\n\t};\n}\nvar ARROW_KEYS = [\n\t\"ArrowUp\",\n\t\"ArrowDown\",\n\t\"ArrowLeft\",\n\t\"ArrowRight\"\n];\nvar useRadioGroupItem = function(params) {\n\tvar { radioGroupContext, value, labelledBy: ariaLabelledby, disabled: itemDisabled, ref: refProp, id, onPress, onKeyDown, onFocus } = params;\n\tvar { value: groupValue, disabled, required, onChange, name, native, accentColor } = useContext(radioGroupContext);\n\tvar [button, setButton] = useState(null);\n\tvar hasConsumerStoppedPropagationRef = useRef(false);\n\tvar ref = useRef(null);\n\tvar composedRefs = useComposedRefs(refProp, function(node) {\n\t\treturn setButton(node);\n\t}, ref);\n\tvar isArrowKeyPressedRef = useRef(false);\n\tvar isFormControl = isWeb ? button ? Boolean(button.closest(\"form\")) : true : false;\n\tvar checked = groupValue === value;\n\tvar labelId = useLabelContext(button);\n\tvar labelledBy = ariaLabelledby || labelId;\n\tuseEffect(function() {\n\t\tif (isWeb) {\n\t\t\tvar handleKeyDown = function(event) {\n\t\t\t\tif (ARROW_KEYS.includes(event.key)) isArrowKeyPressedRef.current = true;\n\t\t\t};\n\t\t\tvar handleKeyUp = function() {\n\t\t\t\tisArrowKeyPressedRef.current = false;\n\t\t\t};\n\t\t\tdocument.addEventListener(\"keydown\", handleKeyDown);\n\t\t\tdocument.addEventListener(\"keyup\", handleKeyUp);\n\t\t\treturn function() {\n\t\t\t\tdocument.removeEventListener(\"keydown\", handleKeyDown);\n\t\t\t\tdocument.removeEventListener(\"keyup\", handleKeyUp);\n\t\t\t};\n\t\t}\n\t}, []);\n\tuseEffect(function() {\n\t\tif (!id) return;\n\t\tif (disabled) return;\n\t\treturn registerFocusable(id, {\n\t\t\tfocusAndSelect: function() {\n\t\t\t\tonChange === null || onChange === void 0 || onChange(value);\n\t\t\t},\n\t\t\tfocus: function() {}\n\t\t});\n\t}, [\n\t\tid,\n\t\tvalue,\n\t\tdisabled\n\t]);\n\tvar isDisabled = disabled || itemDisabled;\n\treturn {\n\t\tproviderValue: { checked },\n\t\tchecked,\n\t\tisFormControl,\n\t\tbubbleInput: /* @__PURE__ */ jsx(BubbleInput, {\n\t\t\tisHidden: !native,\n\t\t\tcontrol: button,\n\t\t\tbubbles: !hasConsumerStoppedPropagationRef.current,\n\t\t\tname,\n\t\t\tvalue,\n\t\t\tchecked,\n\t\t\trequired,\n\t\t\tdisabled: isDisabled,\n\t\t\t...isWeb && native && {\n\t\t\t\taccentColor,\n\t\t\t\tid\n\t\t\t}\n\t\t}),\n\t\tnative,\n\t\tframeAttrs: {\n\t\t\t\"data-state\": getState(checked),\n\t\t\t\"data-disabled\": isDisabled ? \"\" : void 0,\n\t\t\trole: \"radio\",\n\t\t\t\"aria-labelledby\": labelledBy,\n\t\t\t\"aria-checked\": checked,\n\t\t\t\"aria-required\": required,\n\t\t\tdisabled: isDisabled,\n\t\t\tref: composedRefs,\n\t\t\t...isWeb && {\n\t\t\t\ttype: \"button\",\n\t\t\t\tvalue\n\t\t\t},\n\t\t\tid,\n\t\t\tonPress: composeEventHandlers(onPress, function(event) {\n\t\t\t\tif (!checked) onChange === null || onChange === void 0 || onChange(value);\n\t\t\t\tif (isFormControl) {\n\t\t\t\t\thasConsumerStoppedPropagationRef.current = event.isPropagationStopped();\n\t\t\t\t\tif (!hasConsumerStoppedPropagationRef.current) event.stopPropagation();\n\t\t\t\t}\n\t\t\t}),\n\t\t\t...isWeb && {\n\t\t\t\tonKeyDown: composeEventHandlers(function(event) {\n\t\t\t\t\tif (\"key\" in event) onKeyDown === null || onKeyDown === void 0 || onKeyDown(event);\n\t\t\t\t}, function(event) {\n\t\t\t\t\tvar { key } = event.nativeEvent;\n\t\t\t\t\tif (key === \"Enter\" || key === \" \") {\n\t\t\t\t\t\tif (!checked) onChange === null || onChange === void 0 || onChange(value);\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t\tonFocus: composeEventHandlers(function(event) {\n\t\t\t\t\tif (\"relatedTarget\" in event) onFocus === null || onFocus === void 0 || onFocus(event);\n\t\t\t\t}, function() {\n\t\t\t\t\tif (isArrowKeyPressedRef.current) {\n\t\t\t\t\t\tvar _ref_current;\n\t\t\t\t\t\t(_ref_current = ref.current) === null || _ref_current === void 0 || _ref_current.click();\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t}\n\t\t},\n\t\trovingFocusGroupAttrs: {\n\t\t\tasChild: \"except-style\",\n\t\t\ttabIndex: isDisabled ? -1 : 0,\n\t\t\tactive: checked\n\t\t}\n\t};\n};\nfunction useRadioGroupItemIndicator(params) {\n\tvar { radioGroupItemContext, disabled, ...rest } = params;\n\tvar { checked } = useContext(radioGroupItemContext);\n\treturn {\n\t\tchecked,\n\t\t\"data-state\": getState(checked),\n\t\t\"data-disabled\": disabled ? \"\" : void 0,\n\t\t...rest\n\t};\n}\n\nexport { useRadioGroup, useRadioGroupItem, useRadioGroupItemIndicator };"],"mappings":";;;;;;;;;;;;AAWA,SAAS,cAAc,QAAQ;CAC9B,IAAI,EAAE,OAAO,WAAW,eAAe,cAAc,UAAU,UAAU,MAAM,QAAQ,aAAa,aAAa,QAAQ;CACzH,IAAI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AO;KAC7C,IAAI,mBAAmB,OAAO,YAAY,QAAQ,YAAY,KAAK,KAAK,QAAQ,KAAK;IACtF,GAAG,WAAW;KACb,IAAI,qBAAqB,SAAS;MACjC,IAAI;MACJ,CAAC,eAAe,IAAI,aAAa,QAAQ,iBAAiB,KAAK,KAAK,aAAa,MAAM;KACxF;IACD,CAAC;GACF;EACD;EACA,uBAAuB;GACtB,SAAS;GACT,UAAU,aAAa,CAAC,IAAI;GAC5B,QAAQ;EACT;CACD;AACD;AACA,SAAS,2BAA2B,QAAQ;CAC3C,IAAI,EAAE,uBAAuB,UAAU,GAAG,SAAS;CACnD,IAAI,EAAE,YAAY,WAAW,qBAAqB;CAClD,OAAO;EACN;EACA,cAAc,SAAS,OAAO;EAC9B,iBAAiB,WAAW,KAAK,KAAK;EACtC,GAAG;CACJ;AACD"}
|
|
@@ -112,12 +112,17 @@ const useRadioGroupItem = (params) => {
|
|
|
112
112
|
}
|
|
113
113
|
}),
|
|
114
114
|
...isWeb && {
|
|
115
|
-
onKeyDown: composeEventHandlers(
|
|
116
|
-
if (
|
|
115
|
+
onKeyDown: composeEventHandlers((event) => {
|
|
116
|
+
if ("key" in event) onKeyDown?.(event);
|
|
117
|
+
}, (event) => {
|
|
118
|
+
const { key } = event.nativeEvent;
|
|
119
|
+
if (key === "Enter" || key === " ") {
|
|
117
120
|
if (!checked) onChange?.(value);
|
|
118
121
|
}
|
|
119
122
|
}),
|
|
120
|
-
onFocus: composeEventHandlers(
|
|
123
|
+
onFocus: composeEventHandlers((event) => {
|
|
124
|
+
if ("relatedTarget" in event) onFocus?.(event);
|
|
125
|
+
}, () => {
|
|
121
126
|
if (isArrowKeyPressedRef.current) ref.current?.click();
|
|
122
127
|
})
|
|
123
128
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRadioGroup.js","names":[],"sources":["jsx/useRadioGroup.js"],"sourcesContent":["import { useComposedRefs } from \"@tamagui/compose-refs\";\nimport { isWeb } from \"@tamagui/constants\";\nimport { composeEventHandlers } from \"@tamagui/helpers\";\nimport { useLabelContext } from \"@tamagui/label\";\nimport { useControllableState } from \"@tamagui/use-controllable-state\";\nimport { useContext, useEffect, useRef, useState } from \"react\";\nimport { BubbleInput } from \"./BubbleInput\";\nimport { getState } from \"./utils\";\nimport { jsx } from \"react/jsx-runtime\";\n\nfunction useRadioGroup(params) {\n\tconst { value: valueProp, onValueChange, defaultValue, required, disabled, name, native, accentColor, orientation, ref } = params;\n\tconst [value, setValue] = useControllableState({\n\t\tprop: valueProp,\n\t\tdefaultProp: defaultValue,\n\t\tonChange: onValueChange\n\t});\n\treturn {\n\t\tproviderValue: {\n\t\t\tvalue,\n\t\t\tonChange: setValue,\n\t\t\trequired,\n\t\t\tdisabled,\n\t\t\tname,\n\t\t\tnative,\n\t\t\taccentColor\n\t\t},\n\t\tframeAttrs: {\n\t\t\trole: \"radiogroup\",\n\t\t\t\"aria-orientation\": orientation,\n\t\t\t\"data-disabled\": disabled ? \"\" : void 0\n\t\t},\n\t\trovingFocusGroupAttrs: {\n\t\t\torientation,\n\t\t\tloop: true\n\t\t}\n\t};\n}\nconst ARROW_KEYS = [\n\t\"ArrowUp\",\n\t\"ArrowDown\",\n\t\"ArrowLeft\",\n\t\"ArrowRight\"\n];\nconst useRadioGroupItem = (params) => {\n\tconst { radioGroupContext, value, labelledBy: ariaLabelledby, disabled: itemDisabled, ref: refProp, id, onPress, onKeyDown, onFocus } = params;\n\tconst { value: groupValue, disabled, required, onChange, name, native, accentColor } = useContext(radioGroupContext);\n\tconst [button, setButton] = useState(null);\n\tconst hasConsumerStoppedPropagationRef = useRef(false);\n\tconst ref = useRef(null);\n\tconst composedRefs = useComposedRefs(refProp, (node) => setButton(node), ref);\n\tconst isArrowKeyPressedRef = useRef(false);\n\tconst isFormControl = isWeb ? button ? Boolean(button.closest(\"form\")) : true : false;\n\tconst checked = groupValue === value;\n\tconst labelId = useLabelContext(button);\n\tconst labelledBy = ariaLabelledby || labelId;\n\tuseEffect(() => {\n\t\tif (isWeb) {\n\t\t\tconst handleKeyDown = (event) => {\n\t\t\t\tif (ARROW_KEYS.includes(event.key)) isArrowKeyPressedRef.current = true;\n\t\t\t};\n\t\t\tconst handleKeyUp = () => {\n\t\t\t\tisArrowKeyPressedRef.current = false;\n\t\t\t};\n\t\t\tdocument.addEventListener(\"keydown\", handleKeyDown);\n\t\t\tdocument.addEventListener(\"keyup\", handleKeyUp);\n\t\t\treturn () => {\n\t\t\t\tdocument.removeEventListener(\"keydown\", handleKeyDown);\n\t\t\t\tdocument.removeEventListener(\"keyup\", handleKeyUp);\n\t\t\t};\n\t\t}\n\t}, []);\n\tconst isDisabled = disabled || itemDisabled;\n\treturn {\n\t\tproviderValue: { checked },\n\t\tchecked,\n\t\tisFormControl,\n\t\tbubbleInput: /* @__PURE__ */ jsx(BubbleInput, {\n\t\t\tisHidden: !native,\n\t\t\tcontrol: button,\n\t\t\tbubbles: !hasConsumerStoppedPropagationRef.current,\n\t\t\tname,\n\t\t\tvalue,\n\t\t\tchecked,\n\t\t\trequired,\n\t\t\tdisabled: isDisabled,\n\t\t\t...isWeb && native && {\n\t\t\t\taccentColor,\n\t\t\t\tid\n\t\t\t}\n\t\t}),\n\t\tnative,\n\t\tframeAttrs: {\n\t\t\t\"data-state\": getState(checked),\n\t\t\t\"data-disabled\": isDisabled ? \"\" : void 0,\n\t\t\trole: \"radio\",\n\t\t\t\"aria-labelledby\": labelledBy,\n\t\t\t\"aria-checked\": checked,\n\t\t\t\"aria-required\": required,\n\t\t\tdisabled: isDisabled,\n\t\t\tref: composedRefs,\n\t\t\t...isWeb && {\n\t\t\t\ttype: \"button\",\n\t\t\t\tvalue\n\t\t\t},\n\t\t\tid,\n\t\t\tonPress: composeEventHandlers(onPress, (event) => {\n\t\t\t\tif (!checked) onChange?.(value);\n\t\t\t\tif (isFormControl) {\n\t\t\t\t\thasConsumerStoppedPropagationRef.current = event.isPropagationStopped();\n\t\t\t\t\tif (!hasConsumerStoppedPropagationRef.current) event.stopPropagation();\n\t\t\t\t}\n\t\t\t}),\n\t\t\t...isWeb && {\n\t\t\t\tonKeyDown: composeEventHandlers(onKeyDown, (event) => {\n\t\t\t\t\tif (
|
|
1
|
+
{"version":3,"file":"useRadioGroup.js","names":[],"sources":["jsx/useRadioGroup.js"],"sourcesContent":["import { useComposedRefs } from \"@tamagui/compose-refs\";\nimport { isWeb } from \"@tamagui/constants\";\nimport { composeEventHandlers } from \"@tamagui/helpers\";\nimport { useLabelContext } from \"@tamagui/label\";\nimport { useControllableState } from \"@tamagui/use-controllable-state\";\nimport { useContext, useEffect, useRef, useState } from \"react\";\nimport { BubbleInput } from \"./BubbleInput\";\nimport { getState } from \"./utils\";\nimport { jsx } from \"react/jsx-runtime\";\n\nfunction useRadioGroup(params) {\n\tconst { value: valueProp, onValueChange, defaultValue, required, disabled, name, native, accentColor, orientation, ref } = params;\n\tconst [value, setValue] = useControllableState({\n\t\tprop: valueProp,\n\t\tdefaultProp: defaultValue,\n\t\tonChange: onValueChange\n\t});\n\treturn {\n\t\tproviderValue: {\n\t\t\tvalue,\n\t\t\tonChange: setValue,\n\t\t\trequired,\n\t\t\tdisabled,\n\t\t\tname,\n\t\t\tnative,\n\t\t\taccentColor\n\t\t},\n\t\tframeAttrs: {\n\t\t\trole: \"radiogroup\",\n\t\t\t\"aria-orientation\": orientation,\n\t\t\t\"data-disabled\": disabled ? \"\" : void 0\n\t\t},\n\t\trovingFocusGroupAttrs: {\n\t\t\torientation,\n\t\t\tloop: true\n\t\t}\n\t};\n}\nconst ARROW_KEYS = [\n\t\"ArrowUp\",\n\t\"ArrowDown\",\n\t\"ArrowLeft\",\n\t\"ArrowRight\"\n];\nconst useRadioGroupItem = (params) => {\n\tconst { radioGroupContext, value, labelledBy: ariaLabelledby, disabled: itemDisabled, ref: refProp, id, onPress, onKeyDown, onFocus } = params;\n\tconst { value: groupValue, disabled, required, onChange, name, native, accentColor } = useContext(radioGroupContext);\n\tconst [button, setButton] = useState(null);\n\tconst hasConsumerStoppedPropagationRef = useRef(false);\n\tconst ref = useRef(null);\n\tconst composedRefs = useComposedRefs(refProp, (node) => setButton(node), ref);\n\tconst isArrowKeyPressedRef = useRef(false);\n\tconst isFormControl = isWeb ? button ? Boolean(button.closest(\"form\")) : true : false;\n\tconst checked = groupValue === value;\n\tconst labelId = useLabelContext(button);\n\tconst labelledBy = ariaLabelledby || labelId;\n\tuseEffect(() => {\n\t\tif (isWeb) {\n\t\t\tconst handleKeyDown = (event) => {\n\t\t\t\tif (ARROW_KEYS.includes(event.key)) isArrowKeyPressedRef.current = true;\n\t\t\t};\n\t\t\tconst handleKeyUp = () => {\n\t\t\t\tisArrowKeyPressedRef.current = false;\n\t\t\t};\n\t\t\tdocument.addEventListener(\"keydown\", handleKeyDown);\n\t\t\tdocument.addEventListener(\"keyup\", handleKeyUp);\n\t\t\treturn () => {\n\t\t\t\tdocument.removeEventListener(\"keydown\", handleKeyDown);\n\t\t\t\tdocument.removeEventListener(\"keyup\", handleKeyUp);\n\t\t\t};\n\t\t}\n\t}, []);\n\tconst isDisabled = disabled || itemDisabled;\n\treturn {\n\t\tproviderValue: { checked },\n\t\tchecked,\n\t\tisFormControl,\n\t\tbubbleInput: /* @__PURE__ */ jsx(BubbleInput, {\n\t\t\tisHidden: !native,\n\t\t\tcontrol: button,\n\t\t\tbubbles: !hasConsumerStoppedPropagationRef.current,\n\t\t\tname,\n\t\t\tvalue,\n\t\t\tchecked,\n\t\t\trequired,\n\t\t\tdisabled: isDisabled,\n\t\t\t...isWeb && native && {\n\t\t\t\taccentColor,\n\t\t\t\tid\n\t\t\t}\n\t\t}),\n\t\tnative,\n\t\tframeAttrs: {\n\t\t\t\"data-state\": getState(checked),\n\t\t\t\"data-disabled\": isDisabled ? \"\" : void 0,\n\t\t\trole: \"radio\",\n\t\t\t\"aria-labelledby\": labelledBy,\n\t\t\t\"aria-checked\": checked,\n\t\t\t\"aria-required\": required,\n\t\t\tdisabled: isDisabled,\n\t\t\tref: composedRefs,\n\t\t\t...isWeb && {\n\t\t\t\ttype: \"button\",\n\t\t\t\tvalue\n\t\t\t},\n\t\t\tid,\n\t\t\tonPress: composeEventHandlers(onPress, (event) => {\n\t\t\t\tif (!checked) onChange?.(value);\n\t\t\t\tif (isFormControl) {\n\t\t\t\t\thasConsumerStoppedPropagationRef.current = event.isPropagationStopped();\n\t\t\t\t\tif (!hasConsumerStoppedPropagationRef.current) event.stopPropagation();\n\t\t\t\t}\n\t\t\t}),\n\t\t\t...isWeb && {\n\t\t\t\tonKeyDown: composeEventHandlers((event) => {\n\t\t\t\t\tif (\"key\" in event) onKeyDown?.(event);\n\t\t\t\t}, (event) => {\n\t\t\t\t\tconst { key } = event.nativeEvent;\n\t\t\t\t\tif (key === \"Enter\" || key === \" \") {\n\t\t\t\t\t\tif (!checked) onChange?.(value);\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t\tonFocus: composeEventHandlers((event) => {\n\t\t\t\t\tif (\"relatedTarget\" in event) onFocus?.(event);\n\t\t\t\t}, () => {\n\t\t\t\t\tif (isArrowKeyPressedRef.current) ref.current?.click();\n\t\t\t\t})\n\t\t\t}\n\t\t},\n\t\trovingFocusGroupAttrs: {\n\t\t\tasChild: \"except-style\",\n\t\t\ttabIndex: isDisabled ? -1 : 0,\n\t\t\tactive: checked\n\t\t}\n\t};\n};\nfunction useRadioGroupItemIndicator(params) {\n\tconst { radioGroupItemContext, disabled, ...rest } = params;\n\tconst { checked } = useContext(radioGroupItemContext);\n\treturn {\n\t\tchecked,\n\t\t\"data-state\": getState(checked),\n\t\t\"data-disabled\": disabled ? \"\" : void 0,\n\t\t...rest\n\t};\n}\n\nexport { useRadioGroup, useRadioGroupItem, useRadioGroupItemIndicator };"],"mappings":";;;;;;;;;;;AAUA,SAAS,cAAc,QAAQ;CAC9B,MAAM,EAAE,OAAO,WAAW,eAAe,cAAc,UAAU,UAAU,MAAM,QAAQ,aAAa,aAAa,QAAQ;CAC3H,MAAM,CAAC,OAAO,YAAY,qBA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 +157,17 @@ var useRadioGroupItem = function(params) {
|
|
|
157
157
|
}
|
|
158
158
|
}),
|
|
159
159
|
...import_constants.isWeb && {
|
|
160
|
-
onKeyDown: (0, import_helpers.composeEventHandlers)(
|
|
161
|
-
if (
|
|
160
|
+
onKeyDown: (0, import_helpers.composeEventHandlers)(function(event) {
|
|
161
|
+
if ("key" in event) onKeyDown === null || onKeyDown === void 0 || onKeyDown(event);
|
|
162
|
+
}, function(event) {
|
|
163
|
+
var { key } = event.nativeEvent;
|
|
164
|
+
if (key === "Enter" || key === " ") {
|
|
162
165
|
if (!checked) onChange === null || onChange === void 0 || onChange(value);
|
|
163
166
|
}
|
|
164
167
|
}),
|
|
165
|
-
onFocus: (0, import_helpers.composeEventHandlers)(
|
|
168
|
+
onFocus: (0, import_helpers.composeEventHandlers)(function(event) {
|
|
169
|
+
if ("relatedTarget" in event) onFocus === null || onFocus === void 0 || onFocus(event);
|
|
170
|
+
}, function() {
|
|
166
171
|
if (isArrowKeyPressedRef.current) {
|
|
167
172
|
var _ref_current;
|
|
168
173
|
(_ref_current = ref.current) === null || _ref_current === void 0 || _ref_current.click();
|
|
@@ -157,12 +157,17 @@ var useRadioGroupItem = function(params) {
|
|
|
157
157
|
}
|
|
158
158
|
}),
|
|
159
159
|
...import_constants.isWeb && {
|
|
160
|
-
onKeyDown: (0, import_helpers.composeEventHandlers)(
|
|
161
|
-
if (
|
|
160
|
+
onKeyDown: (0, import_helpers.composeEventHandlers)(function(event) {
|
|
161
|
+
if ("key" in event) onKeyDown === null || onKeyDown === void 0 || onKeyDown(event);
|
|
162
|
+
}, function(event) {
|
|
163
|
+
var { key } = event.nativeEvent;
|
|
164
|
+
if (key === "Enter" || key === " ") {
|
|
162
165
|
if (!checked) onChange === null || onChange === void 0 || onChange(value);
|
|
163
166
|
}
|
|
164
167
|
}),
|
|
165
|
-
onFocus: (0, import_helpers.composeEventHandlers)(
|
|
168
|
+
onFocus: (0, import_helpers.composeEventHandlers)(function(event) {
|
|
169
|
+
if ("relatedTarget" in event) onFocus === null || onFocus === void 0 || onFocus(event);
|
|
170
|
+
}, function() {
|
|
166
171
|
if (isArrowKeyPressedRef.current) {
|
|
167
172
|
var _ref_current;
|
|
168
173
|
(_ref_current = ref.current) === null || _ref_current === void 0 || _ref_current.click();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRadioGroup.native.js","names":[],"sources":["jsx/useRadioGroup.native.js"],"sourcesContent":["\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n\tfor (var name in all) __defProp(target, name, {\n\t\tget: all[name],\n\t\tenumerable: true\n\t});\n};\nvar __copyProps = (to, from, except, desc) => {\n\tif (from && typeof from === \"object\" || typeof from === \"function\") {\n\t\tfor (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {\n\t\t\tget: () => from[key],\n\t\t\tenumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable\n\t\t});\n\t}\n\treturn to;\n};\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar useRadioGroup_exports = {};\n__export(useRadioGroup_exports, {\n\tuseRadioGroup: () => useRadioGroup,\n\tuseRadioGroupItem: () => useRadioGroupItem,\n\tuseRadioGroupItemIndicator: () => useRadioGroupItemIndicator\n});\nmodule.exports = __toCommonJS(useRadioGroup_exports);\nvar import_jsx_runtime = require(\"react/jsx-runtime\");\nvar import_compose_refs = require(\"@tamagui/compose-refs\");\nvar import_constants = require(\"@tamagui/constants\");\nvar import_focusable = require(\"@tamagui/focusable\");\nvar import_helpers = require(\"@tamagui/helpers\");\nvar import_label = require(\"@tamagui/label\");\nvar import_use_controllable_state = require(\"@tamagui/use-controllable-state\");\nvar import_react = require(\"react\");\nvar import_BubbleInput = require(\"./BubbleInput\");\nvar import_utils = require(\"./utils\");\nfunction useRadioGroup(params) {\n\tvar { value: valueProp, onValueChange, defaultValue, required, disabled, name, native, accentColor, orientation, ref } = params;\n\tvar [value, setValue] = (0, import_use_controllable_state.useControllableState)({\n\t\tprop: valueProp,\n\t\tdefaultProp: defaultValue,\n\t\tonChange: onValueChange\n\t});\n\treturn {\n\t\tproviderValue: {\n\t\t\tvalue,\n\t\t\tonChange: setValue,\n\t\t\trequired,\n\t\t\tdisabled,\n\t\t\tname,\n\t\t\tnative,\n\t\t\taccentColor\n\t\t},\n\t\tframeAttrs: {\n\t\t\trole: \"radiogroup\",\n\t\t\t\"aria-orientation\": orientation,\n\t\t\t\"data-disabled\": disabled ? \"\" : void 0\n\t\t},\n\t\trovingFocusGroupAttrs: {\n\t\t\torientation,\n\t\t\tloop: true\n\t\t}\n\t};\n}\nvar ARROW_KEYS = [\n\t\"ArrowUp\",\n\t\"ArrowDown\",\n\t\"ArrowLeft\",\n\t\"ArrowRight\"\n];\nvar useRadioGroupItem = function(params) {\n\tvar { radioGroupContext, value, labelledBy: ariaLabelledby, disabled: itemDisabled, ref: refProp, id, onPress, onKeyDown, onFocus } = params;\n\tvar { value: groupValue, disabled, required, onChange, name, native, accentColor } = (0, import_react.useContext)(radioGroupContext);\n\tvar [button, setButton] = (0, import_react.useState)(null);\n\tvar hasConsumerStoppedPropagationRef = (0, import_react.useRef)(false);\n\tvar ref = (0, import_react.useRef)(null);\n\tvar composedRefs = (0, import_compose_refs.useComposedRefs)(refProp, function(node) {\n\t\treturn setButton(node);\n\t}, ref);\n\tvar isArrowKeyPressedRef = (0, import_react.useRef)(false);\n\tvar isFormControl = import_constants.isWeb ? button ? Boolean(button.closest(\"form\")) : true : false;\n\tvar checked = groupValue === value;\n\tvar labelId = (0, import_label.useLabelContext)(button);\n\tvar labelledBy = ariaLabelledby || labelId;\n\t(0, import_react.useEffect)(function() {\n\t\tif (import_constants.isWeb) {\n\t\t\tvar handleKeyDown = function(event) {\n\t\t\t\tif (ARROW_KEYS.includes(event.key)) isArrowKeyPressedRef.current = true;\n\t\t\t};\n\t\t\tvar handleKeyUp = function() {\n\t\t\t\tisArrowKeyPressedRef.current = false;\n\t\t\t};\n\t\t\tdocument.addEventListener(\"keydown\", handleKeyDown);\n\t\t\tdocument.addEventListener(\"keyup\", handleKeyUp);\n\t\t\treturn function() {\n\t\t\t\tdocument.removeEventListener(\"keydown\", handleKeyDown);\n\t\t\t\tdocument.removeEventListener(\"keyup\", handleKeyUp);\n\t\t\t};\n\t\t}\n\t}, []);\n\t(0, import_react.useEffect)(function() {\n\t\tif (!id) return;\n\t\tif (disabled) return;\n\t\treturn (0, import_focusable.registerFocusable)(id, {\n\t\t\tfocusAndSelect: function() {\n\t\t\t\tonChange === null || onChange === void 0 || onChange(value);\n\t\t\t},\n\t\t\tfocus: function() {}\n\t\t});\n\t}, [\n\t\tid,\n\t\tvalue,\n\t\tdisabled\n\t]);\n\tvar isDisabled = disabled || itemDisabled;\n\treturn {\n\t\tproviderValue: { checked },\n\t\tchecked,\n\t\tisFormControl,\n\t\tbubbleInput: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_BubbleInput.BubbleInput, {\n\t\t\tisHidden: !native,\n\t\t\tcontrol: button,\n\t\t\tbubbles: !hasConsumerStoppedPropagationRef.current,\n\t\t\tname,\n\t\t\tvalue,\n\t\t\tchecked,\n\t\t\trequired,\n\t\t\tdisabled: isDisabled,\n\t\t\t...import_constants.isWeb && native && {\n\t\t\t\taccentColor,\n\t\t\t\tid\n\t\t\t}\n\t\t}),\n\t\tnative,\n\t\tframeAttrs: {\n\t\t\t\"data-state\": (0, import_utils.getState)(checked),\n\t\t\t\"data-disabled\": isDisabled ? \"\" : void 0,\n\t\t\trole: \"radio\",\n\t\t\t\"aria-labelledby\": labelledBy,\n\t\t\t\"aria-checked\": checked,\n\t\t\t\"aria-required\": required,\n\t\t\tdisabled: isDisabled,\n\t\t\tref: composedRefs,\n\t\t\t...import_constants.isWeb && {\n\t\t\t\ttype: \"button\",\n\t\t\t\tvalue\n\t\t\t},\n\t\t\tid,\n\t\t\tonPress: (0, import_helpers.composeEventHandlers)(onPress, function(event) {\n\t\t\t\tif (!checked) onChange === null || onChange === void 0 || onChange(value);\n\t\t\t\tif (isFormControl) {\n\t\t\t\t\thasConsumerStoppedPropagationRef.current = event.isPropagationStopped();\n\t\t\t\t\tif (!hasConsumerStoppedPropagationRef.current) event.stopPropagation();\n\t\t\t\t}\n\t\t\t}),\n\t\t\t...import_constants.isWeb && {\n\t\t\t\tonKeyDown: (0, import_helpers.composeEventHandlers)(onKeyDown, function(event) {\n\t\t\t\t\tif (event.key === \"Enter\" || event.key === \" \") {\n\t\t\t\t\t\tif (!checked) onChange === null || onChange === void 0 || onChange(value);\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t\tonFocus: (0, import_helpers.composeEventHandlers)(onFocus, function() {\n\t\t\t\t\tif (isArrowKeyPressedRef.current) {\n\t\t\t\t\t\tvar _ref_current;\n\t\t\t\t\t\t(_ref_current = ref.current) === null || _ref_current === void 0 || _ref_current.click();\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t}\n\t\t},\n\t\trovingFocusGroupAttrs: {\n\t\t\tasChild: \"except-style\",\n\t\t\ttabIndex: isDisabled ? -1 : 0,\n\t\t\tactive: checked\n\t\t}\n\t};\n};\nfunction useRadioGroupItemIndicator(params) {\n\tvar { radioGroupItemContext, disabled, ...rest } = params;\n\tvar { checked } = (0, import_react.useContext)(radioGroupItemContext);\n\treturn {\n\t\tchecked,\n\t\t\"data-state\": (0, import_utils.getState)(checked),\n\t\t\"data-disabled\": disabled ? \"\" : void 0,\n\t\t...rest\n\t};\n}\n//# sourceMappingURL=useRadioGroup.js.map\n"],"mappings":";;;AACA,IAAI,YAAY,OAAO;AACvB,IAAI,mBAAmB,OAAO;AAC9B,IAAI,oBAAoB,OAAO;AAC/B,IAAI,eAAe,OAAO,UAAU;AACpC,IAAI,YAAY,QAAQ,QAAQ;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AAM,QAAQ,WAAW,MAAM,QAAQ,KAAK;MAC/C,IAAI,CAAC,SAAS,aAAa,QAAQ,aAAa,KAAK,KAAK,SAAS,KAAK;KACzE;IACD,CAAC;IACD,UAAU,GAAG,eAAe,qBAAoB,CAAE,SAAS,WAAW;KACrE,IAAI,qBAAqB,SAAS;MACjC,IAAI;MACJ,CAAC,eAAe,IAAI,aAAa,QAAQ,iBAAiB,KAAK,KAAK,aAAa,MAAM;KACxF;IACD,CAAC;GACF;EACD;EACA,uBAAuB;GACtB,SAAS;GACT,UAAU,aAAa,CAAC,IAAI;GAC5B,QAAQ;EACT;CACD;AACD;AACA,SAAS,2BAA2B,QAAQ;CAC3C,IAAI,EAAE,uBAAuB,UAAU,GAAG,SAAS;CACnD,IAAI,EAAE,aAAa,GAAG,aAAa,WAAU,CAAE,qBAAqB;CACpE,OAAO;EACN;EACA,eAAe,GAAG,aAAa,SAAQ,CAAE,OAAO;EAChD,iBAAiB,WAAW,KAAK,KAAK;EACtC,GAAG;CACJ;AACD"}
|
|
1
|
+
{"version":3,"file":"useRadioGroup.native.js","names":[],"sources":["jsx/useRadioGroup.native.js"],"sourcesContent":["\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n\tfor (var name in all) __defProp(target, name, {\n\t\tget: all[name],\n\t\tenumerable: true\n\t});\n};\nvar __copyProps = (to, from, except, desc) => {\n\tif (from && typeof from === \"object\" || typeof from === \"function\") {\n\t\tfor (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {\n\t\t\tget: () => from[key],\n\t\t\tenumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable\n\t\t});\n\t}\n\treturn to;\n};\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar useRadioGroup_exports = {};\n__export(useRadioGroup_exports, {\n\tuseRadioGroup: () => useRadioGroup,\n\tuseRadioGroupItem: () => useRadioGroupItem,\n\tuseRadioGroupItemIndicator: () => useRadioGroupItemIndicator\n});\nmodule.exports = __toCommonJS(useRadioGroup_exports);\nvar import_jsx_runtime = require(\"react/jsx-runtime\");\nvar import_compose_refs = require(\"@tamagui/compose-refs\");\nvar import_constants = require(\"@tamagui/constants\");\nvar import_focusable = require(\"@tamagui/focusable\");\nvar import_helpers = require(\"@tamagui/helpers\");\nvar import_label = require(\"@tamagui/label\");\nvar import_use_controllable_state = require(\"@tamagui/use-controllable-state\");\nvar import_react = require(\"react\");\nvar import_BubbleInput = require(\"./BubbleInput\");\nvar import_utils = require(\"./utils\");\nfunction useRadioGroup(params) {\n\tvar { value: valueProp, onValueChange, defaultValue, required, disabled, name, native, accentColor, orientation, ref } = params;\n\tvar [value, setValue] = (0, import_use_controllable_state.useControllableState)({\n\t\tprop: valueProp,\n\t\tdefaultProp: defaultValue,\n\t\tonChange: onValueChange\n\t});\n\treturn {\n\t\tproviderValue: {\n\t\t\tvalue,\n\t\t\tonChange: setValue,\n\t\t\trequired,\n\t\t\tdisabled,\n\t\t\tname,\n\t\t\tnative,\n\t\t\taccentColor\n\t\t},\n\t\tframeAttrs: {\n\t\t\trole: \"radiogroup\",\n\t\t\t\"aria-orientation\": orientation,\n\t\t\t\"data-disabled\": disabled ? \"\" : void 0\n\t\t},\n\t\trovingFocusGroupAttrs: {\n\t\t\torientation,\n\t\t\tloop: true\n\t\t}\n\t};\n}\nvar ARROW_KEYS = [\n\t\"ArrowUp\",\n\t\"ArrowDown\",\n\t\"ArrowLeft\",\n\t\"ArrowRight\"\n];\nvar useRadioGroupItem = function(params) {\n\tvar { radioGroupContext, value, labelledBy: ariaLabelledby, disabled: itemDisabled, ref: refProp, id, onPress, onKeyDown, onFocus } = params;\n\tvar { value: groupValue, disabled, required, onChange, name, native, accentColor } = (0, import_react.useContext)(radioGroupContext);\n\tvar [button, setButton] = (0, import_react.useState)(null);\n\tvar hasConsumerStoppedPropagationRef = (0, import_react.useRef)(false);\n\tvar ref = (0, import_react.useRef)(null);\n\tvar composedRefs = (0, import_compose_refs.useComposedRefs)(refProp, function(node) {\n\t\treturn setButton(node);\n\t}, ref);\n\tvar isArrowKeyPressedRef = (0, import_react.useRef)(false);\n\tvar isFormControl = import_constants.isWeb ? button ? Boolean(button.closest(\"form\")) : true : false;\n\tvar checked = groupValue === value;\n\tvar labelId = (0, import_label.useLabelContext)(button);\n\tvar labelledBy = ariaLabelledby || labelId;\n\t(0, import_react.useEffect)(function() {\n\t\tif (import_constants.isWeb) {\n\t\t\tvar handleKeyDown = function(event) {\n\t\t\t\tif (ARROW_KEYS.includes(event.key)) isArrowKeyPressedRef.current = true;\n\t\t\t};\n\t\t\tvar handleKeyUp = function() {\n\t\t\t\tisArrowKeyPressedRef.current = false;\n\t\t\t};\n\t\t\tdocument.addEventListener(\"keydown\", handleKeyDown);\n\t\t\tdocument.addEventListener(\"keyup\", handleKeyUp);\n\t\t\treturn function() {\n\t\t\t\tdocument.removeEventListener(\"keydown\", handleKeyDown);\n\t\t\t\tdocument.removeEventListener(\"keyup\", handleKeyUp);\n\t\t\t};\n\t\t}\n\t}, []);\n\t(0, import_react.useEffect)(function() {\n\t\tif (!id) return;\n\t\tif (disabled) return;\n\t\treturn (0, import_focusable.registerFocusable)(id, {\n\t\t\tfocusAndSelect: function() {\n\t\t\t\tonChange === null || onChange === void 0 || onChange(value);\n\t\t\t},\n\t\t\tfocus: function() {}\n\t\t});\n\t}, [\n\t\tid,\n\t\tvalue,\n\t\tdisabled\n\t]);\n\tvar isDisabled = disabled || itemDisabled;\n\treturn {\n\t\tproviderValue: { checked },\n\t\tchecked,\n\t\tisFormControl,\n\t\tbubbleInput: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_BubbleInput.BubbleInput, {\n\t\t\tisHidden: !native,\n\t\t\tcontrol: button,\n\t\t\tbubbles: !hasConsumerStoppedPropagationRef.current,\n\t\t\tname,\n\t\t\tvalue,\n\t\t\tchecked,\n\t\t\trequired,\n\t\t\tdisabled: isDisabled,\n\t\t\t...import_constants.isWeb && native && {\n\t\t\t\taccentColor,\n\t\t\t\tid\n\t\t\t}\n\t\t}),\n\t\tnative,\n\t\tframeAttrs: {\n\t\t\t\"data-state\": (0, import_utils.getState)(checked),\n\t\t\t\"data-disabled\": isDisabled ? \"\" : void 0,\n\t\t\trole: \"radio\",\n\t\t\t\"aria-labelledby\": labelledBy,\n\t\t\t\"aria-checked\": checked,\n\t\t\t\"aria-required\": required,\n\t\t\tdisabled: isDisabled,\n\t\t\tref: composedRefs,\n\t\t\t...import_constants.isWeb && {\n\t\t\t\ttype: \"button\",\n\t\t\t\tvalue\n\t\t\t},\n\t\t\tid,\n\t\t\tonPress: (0, import_helpers.composeEventHandlers)(onPress, function(event) {\n\t\t\t\tif (!checked) onChange === null || onChange === void 0 || onChange(value);\n\t\t\t\tif (isFormControl) {\n\t\t\t\t\thasConsumerStoppedPropagationRef.current = event.isPropagationStopped();\n\t\t\t\t\tif (!hasConsumerStoppedPropagationRef.current) event.stopPropagation();\n\t\t\t\t}\n\t\t\t}),\n\t\t\t...import_constants.isWeb && {\n\t\t\t\tonKeyDown: (0, import_helpers.composeEventHandlers)(function(event) {\n\t\t\t\t\tif (\"key\" in event) onKeyDown === null || onKeyDown === void 0 || onKeyDown(event);\n\t\t\t\t}, function(event) {\n\t\t\t\t\tvar { key } = event.nativeEvent;\n\t\t\t\t\tif (key === \"Enter\" || key === \" \") {\n\t\t\t\t\t\tif (!checked) onChange === null || onChange === void 0 || onChange(value);\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t\tonFocus: (0, import_helpers.composeEventHandlers)(function(event) {\n\t\t\t\t\tif (\"relatedTarget\" in event) onFocus === null || onFocus === void 0 || onFocus(event);\n\t\t\t\t}, function() {\n\t\t\t\t\tif (isArrowKeyPressedRef.current) {\n\t\t\t\t\t\tvar _ref_current;\n\t\t\t\t\t\t(_ref_current = ref.current) === null || _ref_current === void 0 || _ref_current.click();\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t}\n\t\t},\n\t\trovingFocusGroupAttrs: {\n\t\t\tasChild: \"except-style\",\n\t\t\ttabIndex: isDisabled ? -1 : 0,\n\t\t\tactive: checked\n\t\t}\n\t};\n};\nfunction useRadioGroupItemIndicator(params) {\n\tvar { radioGroupItemContext, disabled, ...rest } = params;\n\tvar { checked } = (0, import_react.useContext)(radioGroupItemContext);\n\treturn {\n\t\tchecked,\n\t\t\"data-state\": (0, import_utils.getState)(checked),\n\t\t\"data-disabled\": disabled ? \"\" : void 0,\n\t\t...rest\n\t};\n}\n//# sourceMappingURL=useRadioGroup.js.map\n"],"mappings":";;;AACA,IAAI,YAAY,OAAO;AACvB,IAAI,mBAAmB,OAAO;AAC9B,IAAI,oBAAoB,OAAO;AAC/B,IAAI,eAAe,OAAO,UAAU;AACpC,IAAI,YAAY,QAAQ,QAAQ;CAC/B,KAAK,IAAI,QAAQ,KAAK,UAAU,QAAQ,MAAM;EAC7C,KAAK,IAAI;EACT,YAAY;CACb,CAAC;AACF;AACA,IAAI,eAAe,IAAI,MAAM,QAAQ,SAAS;CAC7C,IAAI,QAAQ,OAAO,SAAS,YAAY,OAAO,SAAS,YAAY;EACnE,KAAK,IAAI,OAAO,kBAAkB,IAAI,GAAG,IAAI,CAAC,aAAa,KAAK,IAAI,GAAG,KAAK,QAAQ,QAAQ,UAAU,IAAI,KAAK;GAC9G,WAAW,KAAK;GAChB,YAAY,EAAE,OAAO,iBAAiB,MAAM,GAAG,MAAM,KAAK;EAC3D,CAAC;CACF;CACA,OAAO;AACR;AACA,IAAI,gBAAgB,QAAQ,YAAY,UAAU,CAAC,GAAG,cAAc,EAAE,OAAO,KAAK,CAAC,GAAG,GAAG;AACzF,IAAI,wBAAwB,CAAC;AAC7B,SAAS,uBAAuB;CAC/B,qBAAqB;CACrB,yBAAyB;CACzB,kCAAkC;AACnC,CAA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EAAE,uBAAuB,UAAU,GAAG,SAAS;CACnD,IAAI,EAAE,aAAa,GAAG,aAAa,WAAU,CAAE,qBAAqB;CACpE,OAAO;EACN;EACA,eAAe,GAAG,aAAa,SAAQ,CAAE,OAAO;EAChD,iBAAiB,WAAW,KAAK,KAAK;EACtC,GAAG;CACJ;AACD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/radio-headless",
|
|
3
|
-
"version": "3.0.0
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"license": "MIT",
|
|
4
5
|
"gitHead": "a49cc7ea6b93ba384e77a4880ae48ac4a5635c14",
|
|
5
6
|
"source": "src/index.ts",
|
|
6
7
|
"files": [
|
|
@@ -35,20 +36,21 @@
|
|
|
35
36
|
"clean:build": "tamagui-build clean:build"
|
|
36
37
|
},
|
|
37
38
|
"dependencies": {
|
|
38
|
-
"@tamagui/compose-refs": "3.0.0
|
|
39
|
-
"@tamagui/constants": "3.0.0
|
|
40
|
-
"@tamagui/create-context": "3.0.0
|
|
41
|
-
"@tamagui/focusable": "3.0.0
|
|
42
|
-
"@tamagui/helpers": "3.0.0
|
|
43
|
-
"@tamagui/label": "3.0.0
|
|
44
|
-
"@tamagui/
|
|
45
|
-
"@tamagui/use-
|
|
46
|
-
"@tamagui/
|
|
39
|
+
"@tamagui/compose-refs": "3.0.0",
|
|
40
|
+
"@tamagui/constants": "3.0.0",
|
|
41
|
+
"@tamagui/create-context": "3.0.0",
|
|
42
|
+
"@tamagui/focusable": "3.0.0",
|
|
43
|
+
"@tamagui/helpers": "3.0.0",
|
|
44
|
+
"@tamagui/label": "3.0.0",
|
|
45
|
+
"@tamagui/react-native-types": "3.0.0",
|
|
46
|
+
"@tamagui/use-controllable-state": "3.0.0",
|
|
47
|
+
"@tamagui/use-previous": "3.0.0",
|
|
48
|
+
"@tamagui/web": "3.0.0"
|
|
47
49
|
},
|
|
48
50
|
"devDependencies": {
|
|
49
|
-
"@tamagui/build": "3.0.0
|
|
51
|
+
"@tamagui/build": "3.0.0",
|
|
50
52
|
"react": "19.2.3",
|
|
51
|
-
"react-native": "0.
|
|
53
|
+
"react-native": "0.87.1"
|
|
52
54
|
},
|
|
53
55
|
"peerDependencies": {
|
|
54
56
|
"react": ">=19"
|
|
@@ -59,5 +61,6 @@
|
|
|
59
61
|
"type": "git",
|
|
60
62
|
"url": "git+https://github.com/tamagui/tamagui.git",
|
|
61
63
|
"directory": "code/ui/radio-headless"
|
|
62
|
-
}
|
|
64
|
+
},
|
|
65
|
+
"releaseSourceCommit": "15fbca480b143f876f6975601e23a17d3f90d2ee"
|
|
63
66
|
}
|
package/src/useRadioGroup.tsx
CHANGED
|
@@ -7,7 +7,7 @@ import { useControllableState } from '@tamagui/use-controllable-state'
|
|
|
7
7
|
import type { ViewProps } from '@tamagui/web'
|
|
8
8
|
import type { ReactElement } from 'react'
|
|
9
9
|
import { useContext, useEffect, useRef, useState } from 'react'
|
|
10
|
-
import type { GestureResponderEvent } from 'react-native'
|
|
10
|
+
import type { GestureResponderEvent, PressableProps } from '@tamagui/react-native-types'
|
|
11
11
|
import { BubbleInput } from './BubbleInput'
|
|
12
12
|
import { getState } from './utils'
|
|
13
13
|
|
|
@@ -88,6 +88,10 @@ export type RadioGroupContextValue = {
|
|
|
88
88
|
|
|
89
89
|
const ARROW_KEYS = ['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight']
|
|
90
90
|
|
|
91
|
+
type RadioEvent<K extends 'onKeyDown' | 'onFocus'> =
|
|
92
|
+
| Parameters<NonNullable<ViewProps[K]>>[0]
|
|
93
|
+
| Parameters<NonNullable<PressableProps[K]>>[0]
|
|
94
|
+
|
|
91
95
|
export const useRadioGroupItem = (params: UseRadioItemParams) => {
|
|
92
96
|
const {
|
|
93
97
|
radioGroupContext,
|
|
@@ -210,24 +214,35 @@ export const useRadioGroupItem = (params: UseRadioItemParams) => {
|
|
|
210
214
|
}
|
|
211
215
|
}),
|
|
212
216
|
...(isWeb && {
|
|
213
|
-
onKeyDown: composeEventHandlers(
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
217
|
+
onKeyDown: composeEventHandlers(
|
|
218
|
+
(event: RadioEvent<'onKeyDown'>) => {
|
|
219
|
+
if ('key' in event) onKeyDown?.(event)
|
|
220
|
+
},
|
|
221
|
+
(event) => {
|
|
222
|
+
// react-native-web and native expose the key on nativeEvent.
|
|
223
|
+
const { key } = event.nativeEvent
|
|
224
|
+
if (key === 'Enter' || key === ' ') {
|
|
225
|
+
if (!checked) {
|
|
226
|
+
onChange?.(value)
|
|
227
|
+
}
|
|
218
228
|
}
|
|
219
229
|
}
|
|
220
|
-
|
|
221
|
-
onFocus: composeEventHandlers(
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
230
|
+
),
|
|
231
|
+
onFocus: composeEventHandlers(
|
|
232
|
+
(event: RadioEvent<'onFocus'>) => {
|
|
233
|
+
if ('relatedTarget' in event) onFocus?.(event)
|
|
234
|
+
},
|
|
235
|
+
() => {
|
|
236
|
+
/**
|
|
237
|
+
* Our `RovingFocusGroup` will focus the radio when navigating with arrow keys
|
|
238
|
+
* and we need to "check" it in that case. We click it to "check" it (instead
|
|
239
|
+
* of updating `context.value`) so that the radio change event fires.
|
|
240
|
+
*/
|
|
241
|
+
if (isArrowKeyPressedRef.current) {
|
|
242
|
+
;(ref.current as HTMLButtonElement)?.click()
|
|
243
|
+
}
|
|
229
244
|
}
|
|
230
|
-
|
|
245
|
+
),
|
|
231
246
|
}),
|
|
232
247
|
},
|
|
233
248
|
rovingFocusGroupAttrs: {
|
package/types/useRadioGroup.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ViewProps } from '@tamagui/web';
|
|
2
2
|
import type { ReactElement } from 'react';
|
|
3
|
-
import type {
|
|
3
|
+
import type { PressableProps } from '@tamagui/react-native-types';
|
|
4
4
|
interface UseRadioGroupParams {
|
|
5
5
|
value?: string;
|
|
6
6
|
defaultValue?: string;
|
|
@@ -53,6 +53,7 @@ export type RadioGroupContextValue = {
|
|
|
53
53
|
native?: boolean;
|
|
54
54
|
accentColor?: string;
|
|
55
55
|
};
|
|
56
|
+
type RadioEvent<K extends 'onKeyDown' | 'onFocus'> = Parameters<NonNullable<ViewProps[K]>>[0] | Parameters<NonNullable<PressableProps[K]>>[0];
|
|
56
57
|
export declare const useRadioGroupItem: (params: UseRadioItemParams) => {
|
|
57
58
|
providerValue: {
|
|
58
59
|
checked: boolean;
|
|
@@ -73,9 +74,57 @@ export declare const useRadioGroupItem: (params: UseRadioItemParams) => {
|
|
|
73
74
|
type?: string | undefined;
|
|
74
75
|
value?: string | undefined;
|
|
75
76
|
id: string | undefined;
|
|
76
|
-
onPress: import("@tamagui/helpers").EventHandler<
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
onPress: import("@tamagui/helpers").EventHandler<Readonly<Omit<Readonly<{
|
|
78
|
+
bubbles: boolean | undefined;
|
|
79
|
+
cancelable: boolean | undefined;
|
|
80
|
+
currentTarget: number | import("@tamagui/react-native-types").HostInstance;
|
|
81
|
+
defaultPrevented: boolean | undefined;
|
|
82
|
+
dispatchConfig: Readonly<{
|
|
83
|
+
registrationName: string;
|
|
84
|
+
}>;
|
|
85
|
+
eventPhase: number | undefined;
|
|
86
|
+
preventDefault: () => void;
|
|
87
|
+
isDefaultPrevented: () => boolean;
|
|
88
|
+
stopPropagation: () => void;
|
|
89
|
+
isPropagationStopped: () => boolean;
|
|
90
|
+
isTrusted: boolean | undefined;
|
|
91
|
+
nativeEvent: Readonly<{
|
|
92
|
+
changedTouches: ReadonlyArray<import("@tamagui/react-native-types").NativeTouchEvent>;
|
|
93
|
+
force?: number | undefined;
|
|
94
|
+
identifier: number;
|
|
95
|
+
locationX: number;
|
|
96
|
+
locationY: number;
|
|
97
|
+
pageX: number;
|
|
98
|
+
pageY: number;
|
|
99
|
+
target: number | undefined;
|
|
100
|
+
timestamp: number;
|
|
101
|
+
touches: ReadonlyArray<import("@tamagui/react-native-types").NativeTouchEvent>;
|
|
102
|
+
}>;
|
|
103
|
+
persist: () => void;
|
|
104
|
+
target: (number | undefined) | import("@tamagui/react-native-types").HostInstance;
|
|
105
|
+
timeStamp: number;
|
|
106
|
+
type: string | undefined;
|
|
107
|
+
}>, "touchHistory"> & {
|
|
108
|
+
touchHistory: Readonly<{
|
|
109
|
+
indexOfSingleActiveTouch: number;
|
|
110
|
+
mostRecentTimeStamp: number;
|
|
111
|
+
numberActiveTouches: number;
|
|
112
|
+
touchBank: ReadonlyArray<Readonly<{
|
|
113
|
+
touchActive: boolean;
|
|
114
|
+
startPageX: number;
|
|
115
|
+
startPageY: number;
|
|
116
|
+
startTimeStamp: number;
|
|
117
|
+
currentPageX: number;
|
|
118
|
+
currentPageY: number;
|
|
119
|
+
currentTimeStamp: number;
|
|
120
|
+
previousPageX: number;
|
|
121
|
+
previousPageY: number;
|
|
122
|
+
previousTimeStamp: number;
|
|
123
|
+
}>>;
|
|
124
|
+
}>;
|
|
125
|
+
}>> | undefined;
|
|
126
|
+
onKeyDown?: import("@tamagui/helpers").EventHandler<RadioEvent<"onKeyDown">> | undefined;
|
|
127
|
+
onFocus?: import("@tamagui/helpers").EventHandler<RadioEvent<"onFocus">> | undefined;
|
|
79
128
|
};
|
|
80
129
|
rovingFocusGroupAttrs: {
|
|
81
130
|
asChild: 'except-style';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRadioGroup.d.ts","sourceRoot":"","sources":["../src/useRadioGroup.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AAEzC,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"useRadioGroup.d.ts","sourceRoot":"","sources":["../src/useRadioGroup.ts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