@zag-js/radio-group 1.6.0 → 1.6.2

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/index.d.mts CHANGED
@@ -134,27 +134,31 @@ interface ItemProps {
134
134
  }
135
135
  interface ItemState {
136
136
  /**
137
- * Whether the radio is invalid
137
+ * The value of the item
138
+ */
139
+ value: string;
140
+ /**
141
+ * Whether the item is invalid
138
142
  */
139
143
  invalid: boolean;
140
144
  /**
141
- * Whether the radio is disabled
145
+ * Whether the item is disabled
142
146
  */
143
147
  disabled: boolean;
144
148
  /**
145
- * Whether the radio is checked
149
+ * Whether the item is checked
146
150
  */
147
151
  checked: boolean;
148
152
  /**
149
- * Whether the radio is focused
153
+ * Whether the item is focused
150
154
  */
151
155
  focused: boolean;
152
156
  /**
153
- * Whether the radio is hovered
157
+ * Whether the item is hovered
154
158
  */
155
159
  hovered: boolean;
156
160
  /**
157
- * Whether the radio is active or pressed
161
+ * Whether the item is active or pressed
158
162
  */
159
163
  active: boolean;
160
164
  }
package/dist/index.d.ts CHANGED
@@ -134,27 +134,31 @@ interface ItemProps {
134
134
  }
135
135
  interface ItemState {
136
136
  /**
137
- * Whether the radio is invalid
137
+ * The value of the item
138
+ */
139
+ value: string;
140
+ /**
141
+ * Whether the item is invalid
138
142
  */
139
143
  invalid: boolean;
140
144
  /**
141
- * Whether the radio is disabled
145
+ * Whether the item is disabled
142
146
  */
143
147
  disabled: boolean;
144
148
  /**
145
- * Whether the radio is checked
149
+ * Whether the item is checked
146
150
  */
147
151
  checked: boolean;
148
152
  /**
149
- * Whether the radio is focused
153
+ * Whether the item is focused
150
154
  */
151
155
  focused: boolean;
152
156
  /**
153
- * Whether the radio is hovered
157
+ * Whether the item is hovered
154
158
  */
155
159
  hovered: boolean;
156
160
  /**
157
- * Whether the radio is active or pressed
161
+ * Whether the item is active or pressed
158
162
  */
159
163
  active: boolean;
160
164
  }
package/dist/index.js CHANGED
@@ -59,6 +59,7 @@ function connect(service, normalize) {
59
59
  const readOnly = prop("readOnly");
60
60
  function getItemState(props2) {
61
61
  return {
62
+ value: props2.value,
62
63
  invalid: !!props2.invalid,
63
64
  disabled: !!props2.disabled || groupDisabled,
64
65
  checked: context.get("value") === props2.value,
@@ -68,27 +69,22 @@ function connect(service, normalize) {
68
69
  };
69
70
  }
70
71
  function getItemDataAttrs(props2) {
71
- const radioState = getItemState(props2);
72
+ const itemState = getItemState(props2);
72
73
  return {
73
- "data-focus": domQuery.dataAttr(radioState.focused),
74
- "data-focus-visible": domQuery.dataAttr(radioState.focused && context.get("focusVisible")),
75
- "data-disabled": domQuery.dataAttr(radioState.disabled),
74
+ "data-focus": domQuery.dataAttr(itemState.focused),
75
+ "data-focus-visible": domQuery.dataAttr(itemState.focused && context.get("focusVisible")),
76
+ "data-disabled": domQuery.dataAttr(itemState.disabled),
76
77
  "data-readonly": domQuery.dataAttr(readOnly),
77
- "data-state": radioState.checked ? "checked" : "unchecked",
78
- "data-hover": domQuery.dataAttr(radioState.hovered),
79
- "data-invalid": domQuery.dataAttr(radioState.invalid),
78
+ "data-state": itemState.checked ? "checked" : "unchecked",
79
+ "data-hover": domQuery.dataAttr(itemState.hovered),
80
+ "data-invalid": domQuery.dataAttr(itemState.invalid),
80
81
  "data-orientation": prop("orientation"),
81
82
  "data-ssr": domQuery.dataAttr(context.get("ssr"))
82
83
  };
83
84
  }
84
85
  const focus = () => {
85
- const firstEnabledAndCheckedInput = getFirstEnabledAndCheckedInputEl(scope);
86
- if (firstEnabledAndCheckedInput) {
87
- firstEnabledAndCheckedInput.focus();
88
- return;
89
- }
90
- const firstEnabledInput = getFirstEnabledInputEl(scope);
91
- firstEnabledInput?.focus();
86
+ const nodeToFocus = getFirstEnabledAndCheckedInputEl(scope) ?? getFirstEnabledInputEl(scope);
87
+ nodeToFocus?.focus();
92
88
  };
93
89
  return {
94
90
  focus,
@@ -169,18 +165,18 @@ function connect(service, normalize) {
169
165
  });
170
166
  },
171
167
  getItemControlProps(props2) {
172
- const controlState = getItemState(props2);
168
+ const itemState = getItemState(props2);
173
169
  return normalize.element({
174
170
  ...parts.itemControl.attrs,
175
171
  dir: prop("dir"),
176
172
  id: getItemControlId(scope, props2.value),
177
- "data-active": domQuery.dataAttr(controlState.active),
173
+ "data-active": domQuery.dataAttr(itemState.active),
178
174
  "aria-hidden": true,
179
175
  ...getItemDataAttrs(props2)
180
176
  });
181
177
  },
182
178
  getItemHiddenInputProps(props2) {
183
- const inputState = getItemState(props2);
179
+ const itemState = getItemState(props2);
184
180
  return normalize.input({
185
181
  "data-ownedby": getRootId(scope),
186
182
  id: getItemHiddenInputId(scope, props2.value),
@@ -216,8 +212,8 @@ function connect(service, normalize) {
216
212
  send({ type: "SET_ACTIVE", value: null });
217
213
  }
218
214
  },
219
- disabled: inputState.disabled,
220
- defaultChecked: inputState.checked,
215
+ disabled: itemState.disabled,
216
+ defaultChecked: itemState.checked,
221
217
  style: domQuery.visuallyHiddenStyle
222
218
  });
223
219
  },
package/dist/index.mjs CHANGED
@@ -57,6 +57,7 @@ function connect(service, normalize) {
57
57
  const readOnly = prop("readOnly");
58
58
  function getItemState(props2) {
59
59
  return {
60
+ value: props2.value,
60
61
  invalid: !!props2.invalid,
61
62
  disabled: !!props2.disabled || groupDisabled,
62
63
  checked: context.get("value") === props2.value,
@@ -66,27 +67,22 @@ function connect(service, normalize) {
66
67
  };
67
68
  }
68
69
  function getItemDataAttrs(props2) {
69
- const radioState = getItemState(props2);
70
+ const itemState = getItemState(props2);
70
71
  return {
71
- "data-focus": dataAttr(radioState.focused),
72
- "data-focus-visible": dataAttr(radioState.focused && context.get("focusVisible")),
73
- "data-disabled": dataAttr(radioState.disabled),
72
+ "data-focus": dataAttr(itemState.focused),
73
+ "data-focus-visible": dataAttr(itemState.focused && context.get("focusVisible")),
74
+ "data-disabled": dataAttr(itemState.disabled),
74
75
  "data-readonly": dataAttr(readOnly),
75
- "data-state": radioState.checked ? "checked" : "unchecked",
76
- "data-hover": dataAttr(radioState.hovered),
77
- "data-invalid": dataAttr(radioState.invalid),
76
+ "data-state": itemState.checked ? "checked" : "unchecked",
77
+ "data-hover": dataAttr(itemState.hovered),
78
+ "data-invalid": dataAttr(itemState.invalid),
78
79
  "data-orientation": prop("orientation"),
79
80
  "data-ssr": dataAttr(context.get("ssr"))
80
81
  };
81
82
  }
82
83
  const focus = () => {
83
- const firstEnabledAndCheckedInput = getFirstEnabledAndCheckedInputEl(scope);
84
- if (firstEnabledAndCheckedInput) {
85
- firstEnabledAndCheckedInput.focus();
86
- return;
87
- }
88
- const firstEnabledInput = getFirstEnabledInputEl(scope);
89
- firstEnabledInput?.focus();
84
+ const nodeToFocus = getFirstEnabledAndCheckedInputEl(scope) ?? getFirstEnabledInputEl(scope);
85
+ nodeToFocus?.focus();
90
86
  };
91
87
  return {
92
88
  focus,
@@ -167,18 +163,18 @@ function connect(service, normalize) {
167
163
  });
168
164
  },
169
165
  getItemControlProps(props2) {
170
- const controlState = getItemState(props2);
166
+ const itemState = getItemState(props2);
171
167
  return normalize.element({
172
168
  ...parts.itemControl.attrs,
173
169
  dir: prop("dir"),
174
170
  id: getItemControlId(scope, props2.value),
175
- "data-active": dataAttr(controlState.active),
171
+ "data-active": dataAttr(itemState.active),
176
172
  "aria-hidden": true,
177
173
  ...getItemDataAttrs(props2)
178
174
  });
179
175
  },
180
176
  getItemHiddenInputProps(props2) {
181
- const inputState = getItemState(props2);
177
+ const itemState = getItemState(props2);
182
178
  return normalize.input({
183
179
  "data-ownedby": getRootId(scope),
184
180
  id: getItemHiddenInputId(scope, props2.value),
@@ -214,8 +210,8 @@ function connect(service, normalize) {
214
210
  send({ type: "SET_ACTIVE", value: null });
215
211
  }
216
212
  },
217
- disabled: inputState.disabled,
218
- defaultChecked: inputState.checked,
213
+ disabled: itemState.disabled,
214
+ defaultChecked: itemState.checked,
219
215
  style: visuallyHiddenStyle
220
216
  });
221
217
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/radio-group",
3
- "version": "1.6.0",
3
+ "version": "1.6.2",
4
4
  "description": "Core logic for the radio group widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -27,13 +27,13 @@
27
27
  "url": "https://github.com/chakra-ui/zag/issues"
28
28
  },
29
29
  "dependencies": {
30
- "@zag-js/anatomy": "1.6.0",
31
- "@zag-js/utils": "1.6.0",
32
- "@zag-js/element-rect": "1.6.0",
33
- "@zag-js/core": "1.6.0",
34
- "@zag-js/types": "1.6.0",
35
- "@zag-js/focus-visible": "1.6.0",
36
- "@zag-js/dom-query": "1.6.0"
30
+ "@zag-js/anatomy": "1.6.2",
31
+ "@zag-js/dom-query": "1.6.2",
32
+ "@zag-js/element-rect": "1.6.2",
33
+ "@zag-js/utils": "1.6.2",
34
+ "@zag-js/focus-visible": "1.6.2",
35
+ "@zag-js/core": "1.6.2",
36
+ "@zag-js/types": "1.6.2"
37
37
  },
38
38
  "devDependencies": {
39
39
  "clean-package": "2.2.0"