@zag-js/radio
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -28,2 +28,6 @@ import { RequiredBy, DirectionProperty, CommonProperties, Context, PropTypes, NormalizeProps } from '@zag-js/types'; | ||
/** | ||
* The associate form of the underlying input. | ||
*/ | ||
form?: string; | ||
/** | ||
* If `true`, the radio group will be disabled | ||
@@ -35,3 +39,3 @@ */ | ||
*/ | ||
readonly?: boolean; | ||
readOnly?: boolean; | ||
/** | ||
@@ -67,3 +71,3 @@ * Function called once a radio is checked | ||
*/ | ||
readonly?: boolean; | ||
readOnly?: boolean; | ||
/** | ||
@@ -70,0 +74,0 @@ * If `true`, the radio is marked as invalid. |
@@ -149,6 +149,6 @@ "use strict"; | ||
const isGroupDisabled = state.context.disabled; | ||
const isGroupReadonly = state.context.readonly; | ||
const isGroupReadOnly = state.context.readOnly; | ||
function getRadioState(props) { | ||
const itemState = { | ||
isReadOnly: props.readonly || isGroupReadonly, | ||
isReadOnly: props.readOnly || isGroupReadOnly, | ||
isInvalid: props.invalid, | ||
@@ -270,2 +270,3 @@ isDisabled: props.disabled || isGroupDisabled, | ||
name: state.context.name || state.context.id, | ||
form: state.context.form, | ||
value: props.value, | ||
@@ -378,2 +379,17 @@ onChange(event) { | ||
} | ||
function trackFormControl(el, options) { | ||
if (!el) | ||
return; | ||
const { onFieldsetDisabled, onFormReset } = options; | ||
const cleanups = [ | ||
trackFormReset(el, onFormReset), | ||
trackFieldsetDisabled(el, (disabled) => { | ||
if (disabled) | ||
onFieldsetDisabled(); | ||
}) | ||
]; | ||
return () => { | ||
cleanups.forEach((cleanup) => cleanup == null ? void 0 : cleanup()); | ||
}; | ||
} | ||
@@ -406,3 +422,3 @@ // ../../utilities/core/dist/index.mjs | ||
}, | ||
activities: ["trackFormReset", "trackFieldsetDisabled"], | ||
activities: ["trackFormControlState"], | ||
on: { | ||
@@ -437,13 +453,11 @@ SET_VALUE: { | ||
activities: { | ||
trackFieldsetDisabled(ctx2) { | ||
return trackFieldsetDisabled(dom.getRootEl(ctx2), (disabled) => { | ||
if (disabled) { | ||
ctx2.disabled = disabled; | ||
trackFormControlState(ctx2, _evt, { send }) { | ||
return trackFormControl(dom.getRootEl(ctx2), { | ||
onFieldsetDisabled() { | ||
ctx2.disabled = true; | ||
}, | ||
onFormReset() { | ||
send({ type: "SET_VALUE", value: ctx2.initialValue }); | ||
} | ||
}); | ||
}, | ||
trackFormReset(ctx2, _evt, { send }) { | ||
return trackFormReset(dom.getRootEl(ctx2), () => { | ||
send({ type: "SET_VALUE", value: ctx2.initialValue }); | ||
}); | ||
} | ||
@@ -450,0 +464,0 @@ }, |
{ | ||
"name": "@zag-js/radio", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Core logic for the radio widget implemented as a state machine", | ||
@@ -37,3 +37,3 @@ "main": "dist/index.js", | ||
"@zag-js/dom-utils": "0.2.1", | ||
"@zag-js/form-utils": "0.2.1", | ||
"@zag-js/form-utils": "0.2.2", | ||
"@zag-js/utils": "0.3.1" | ||
@@ -40,0 +40,0 @@ }, |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36815
1048