@pickle-ui/react 1.0.0-beta.13 → 1.0.0-beta.15

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.
Files changed (267) hide show
  1. package/README.md +36 -12
  2. package/dist/components/Alert.d.ts +1 -1
  3. package/dist/components/Alert.d.ts.map +1 -1
  4. package/dist/components/Alert.js.map +1 -1
  5. package/dist/components/AlertDialog.d.ts.map +1 -1
  6. package/dist/components/AlertDialog.js +3 -3
  7. package/dist/components/AlertDialog.js.map +1 -1
  8. package/dist/components/Avatar.d.ts +1 -1
  9. package/dist/components/Avatar.d.ts.map +1 -1
  10. package/dist/components/Avatar.js.map +1 -1
  11. package/dist/components/Badge.d.ts +2 -2
  12. package/dist/components/Badge.d.ts.map +1 -1
  13. package/dist/components/Badge.js.map +1 -1
  14. package/dist/components/Button.d.ts +2 -2
  15. package/dist/components/Button.d.ts.map +1 -1
  16. package/dist/components/Button.js +1 -1
  17. package/dist/components/Button.js.map +1 -1
  18. package/dist/components/Card.d.ts +1 -1
  19. package/dist/components/Card.d.ts.map +1 -1
  20. package/dist/components/Card.js +1 -1
  21. package/dist/components/Card.js.map +1 -1
  22. package/dist/components/Dialog.d.ts.map +1 -1
  23. package/dist/components/Dialog.js.map +1 -1
  24. package/dist/components/Drawer.d.ts +2 -2
  25. package/dist/components/Drawer.d.ts.map +1 -1
  26. package/dist/components/Drawer.js.map +1 -1
  27. package/dist/components/Flex.d.ts +7 -7
  28. package/dist/components/Flex.d.ts.map +1 -1
  29. package/dist/components/Grid.d.ts +42 -42
  30. package/dist/components/Grid.d.ts.map +1 -1
  31. package/dist/components/Grid.js +4 -3
  32. package/dist/components/Grid.js.map +1 -1
  33. package/dist/components/Group.d.ts.map +1 -1
  34. package/dist/components/Group.js.map +1 -1
  35. package/dist/components/Menu.d.ts +1 -1
  36. package/dist/components/Menu.d.ts.map +1 -1
  37. package/dist/components/Menu.js +1 -1
  38. package/dist/components/Menu.js.map +1 -1
  39. package/dist/components/Popover.d.ts.map +1 -1
  40. package/dist/components/Popover.js.map +1 -1
  41. package/dist/components/Progress.d.ts +1 -1
  42. package/dist/components/Progress.d.ts.map +1 -1
  43. package/dist/components/Progress.js +1 -1
  44. package/dist/components/Progress.js.map +1 -1
  45. package/dist/components/ScrollArea.d.ts.map +1 -1
  46. package/dist/components/ScrollArea.js +1 -1
  47. package/dist/components/ScrollArea.js.map +1 -1
  48. package/dist/components/Separator.d.ts.map +1 -1
  49. package/dist/components/Separator.js.map +1 -1
  50. package/dist/components/Sidebar.d.ts.map +1 -1
  51. package/dist/components/Sidebar.js +1 -1
  52. package/dist/components/Sidebar.js.map +1 -1
  53. package/dist/components/Spinner.d.ts.map +1 -1
  54. package/dist/components/Spinner.js.map +1 -1
  55. package/dist/components/Table.d.ts +1 -1
  56. package/dist/components/Table.d.ts.map +1 -1
  57. package/dist/components/Table.js +2 -2
  58. package/dist/components/Table.js.map +1 -1
  59. package/dist/components/Text.d.ts.map +1 -1
  60. package/dist/components/Text.js.map +1 -1
  61. package/dist/components/Toast.d.ts.map +1 -1
  62. package/dist/components/Toast.js +1 -1
  63. package/dist/components/Toast.js.map +1 -1
  64. package/dist/components/Tooltip.d.ts +1 -1
  65. package/dist/components/Tooltip.d.ts.map +1 -1
  66. package/dist/components/Tooltip.js.map +1 -1
  67. package/dist/components/XStack.d.ts.map +1 -1
  68. package/dist/components/XStack.js.map +1 -1
  69. package/dist/components/YStack.d.ts.map +1 -1
  70. package/dist/components/YStack.js.map +1 -1
  71. package/dist/components/_internal/VisuallyHiddenInput.d.ts.map +1 -1
  72. package/dist/components/_internal/VisuallyHiddenInput.js +2 -4
  73. package/dist/components/_internal/VisuallyHiddenInput.js.map +1 -1
  74. package/dist/components/_internal/dialog-styles.d.ts +1 -1
  75. package/dist/components/_internal/dialog-styles.d.ts.map +1 -1
  76. package/dist/components/_internal/dialog-styles.js.map +1 -1
  77. package/dist/components/_internal/layout.d.ts +27 -27
  78. package/dist/components/_internal/layout.d.ts.map +1 -1
  79. package/dist/components/_internal/layout.js +1 -1
  80. package/dist/components/_internal/layout.js.map +1 -1
  81. package/dist/components/_internal/separate.d.ts +1 -1
  82. package/dist/components/_internal/separate.d.ts.map +1 -1
  83. package/dist/components/_internal/separate.js.map +1 -1
  84. package/dist/components/form/Checkbox.d.ts.map +1 -1
  85. package/dist/components/form/Checkbox.js.map +1 -1
  86. package/dist/components/form/ColorPicker.d.ts.map +1 -1
  87. package/dist/components/form/ColorPicker.js.map +1 -1
  88. package/dist/components/form/ColorPickerPrimitive.d.ts.map +1 -1
  89. package/dist/components/form/ColorPickerPrimitive.js +9 -14
  90. package/dist/components/form/ColorPickerPrimitive.js.map +1 -1
  91. package/dist/components/form/Combobox.d.ts.map +1 -1
  92. package/dist/components/form/Combobox.js +11 -12
  93. package/dist/components/form/Combobox.js.map +1 -1
  94. package/dist/components/form/Form.context.d.ts.map +1 -1
  95. package/dist/components/form/Form.context.js +2 -4
  96. package/dist/components/form/Form.context.js.map +1 -1
  97. package/dist/components/form/Form.d.ts +6 -2
  98. package/dist/components/form/Form.d.ts.map +1 -1
  99. package/dist/components/form/Form.js +2 -0
  100. package/dist/components/form/Form.js.map +1 -1
  101. package/dist/components/form/FormCheckbox.d.ts.map +1 -1
  102. package/dist/components/form/FormCheckbox.js.map +1 -1
  103. package/dist/components/form/FormCombobox.d.ts +1 -1
  104. package/dist/components/form/FormCombobox.d.ts.map +1 -1
  105. package/dist/components/form/FormCombobox.js +1 -1
  106. package/dist/components/form/FormCombobox.js.map +1 -1
  107. package/dist/components/form/FormField.d.ts +5 -2
  108. package/dist/components/form/FormField.d.ts.map +1 -1
  109. package/dist/components/form/FormField.js +20 -9
  110. package/dist/components/form/FormField.js.map +1 -1
  111. package/dist/components/form/FormGroupField.d.ts +13 -0
  112. package/dist/components/form/FormGroupField.d.ts.map +1 -0
  113. package/dist/components/form/FormGroupField.js +17 -0
  114. package/dist/components/form/FormGroupField.js.map +1 -0
  115. package/dist/components/form/FormInput.d.ts.map +1 -1
  116. package/dist/components/form/FormInput.js +1 -1
  117. package/dist/components/form/FormInput.js.map +1 -1
  118. package/dist/components/form/FormInputGroup.d.ts.map +1 -1
  119. package/dist/components/form/FormInputGroup.js +2 -6
  120. package/dist/components/form/FormInputGroup.js.map +1 -1
  121. package/dist/components/form/FormRadioGroup.d.ts +1 -1
  122. package/dist/components/form/FormRadioGroup.d.ts.map +1 -1
  123. package/dist/components/form/FormSwitch.d.ts.map +1 -1
  124. package/dist/components/form/FormSwitch.js.map +1 -1
  125. package/dist/components/form/FormTextarea.d.ts.map +1 -1
  126. package/dist/components/form/FormTextarea.js +1 -1
  127. package/dist/components/form/FormTextarea.js.map +1 -1
  128. package/dist/components/form/Input.d.ts.map +1 -1
  129. package/dist/components/form/Input.js.map +1 -1
  130. package/dist/components/form/InputGroup.d.ts +1 -1
  131. package/dist/components/form/InputGroup.d.ts.map +1 -1
  132. package/dist/components/form/InputGroup.js.map +1 -1
  133. package/dist/components/form/RadioGroup.d.ts.map +1 -1
  134. package/dist/components/form/RadioGroup.js.map +1 -1
  135. package/dist/components/form/Select.d.ts.map +1 -1
  136. package/dist/components/form/Select.js +1 -1
  137. package/dist/components/form/Select.js.map +1 -1
  138. package/dist/components/form/Slider.d.ts +1 -1
  139. package/dist/components/form/Slider.d.ts.map +1 -1
  140. package/dist/components/form/Slider.js.map +1 -1
  141. package/dist/components/form/Switch.d.ts.map +1 -1
  142. package/dist/components/form/Switch.js.map +1 -1
  143. package/dist/components/form/Textarea.d.ts.map +1 -1
  144. package/dist/components/form/Textarea.js.map +1 -1
  145. package/dist/entries/checkbox.d.ts +1 -1
  146. package/dist/entries/checkbox.d.ts.map +1 -1
  147. package/dist/entries/form.d.ts +1 -1
  148. package/dist/entries/form.d.ts.map +1 -1
  149. package/dist/entries/group.d.ts +1 -1
  150. package/dist/entries/group.d.ts.map +1 -1
  151. package/dist/entries/radio-group.d.ts +1 -1
  152. package/dist/entries/radio-group.d.ts.map +1 -1
  153. package/dist/lib/color.d.ts +1 -1
  154. package/dist/lib/color.d.ts.map +1 -1
  155. package/dist/lib/color.js +1 -3
  156. package/dist/lib/color.js.map +1 -1
  157. package/dist/lib/compose-refs.js +1 -1
  158. package/dist/lib/compose-refs.js.map +1 -1
  159. package/package.json +35 -34
  160. package/skills/pickle-ui-react/SKILL.md +38 -0
  161. package/src/agent-skill.test.ts +30 -0
  162. package/src/components/Alert.test.tsx +3 -12
  163. package/src/components/Alert.tsx +2 -4
  164. package/src/components/AlertDialog.stories.tsx +10 -35
  165. package/src/components/AlertDialog.test.tsx +6 -23
  166. package/src/components/AlertDialog.tsx +12 -40
  167. package/src/components/Avatar.stories.tsx +3 -8
  168. package/src/components/Avatar.tsx +4 -18
  169. package/src/components/Badge.stories.tsx +1 -5
  170. package/src/components/Badge.test.tsx +1 -4
  171. package/src/components/Badge.tsx +5 -14
  172. package/src/components/Button.stories.tsx +4 -16
  173. package/src/components/Button.test.tsx +8 -9
  174. package/src/components/Button.tsx +2 -7
  175. package/src/components/Card.stories.tsx +1 -3
  176. package/src/components/Card.test.tsx +1 -3
  177. package/src/components/Card.tsx +1 -9
  178. package/src/components/Dialog.stories.tsx +9 -23
  179. package/src/components/Dialog.test.tsx +6 -23
  180. package/src/components/Dialog.tsx +4 -17
  181. package/src/components/Drawer.stories.tsx +9 -34
  182. package/src/components/Drawer.test.tsx +8 -29
  183. package/src/components/Drawer.tsx +4 -15
  184. package/src/components/Grid.stories.tsx +1 -4
  185. package/src/components/Grid.test.tsx +1 -3
  186. package/src/components/Grid.tsx +4 -4
  187. package/src/components/Group.stories.tsx +4 -20
  188. package/src/components/Group.test.tsx +2 -9
  189. package/src/components/Group.tsx +3 -12
  190. package/src/components/Menu.stories.tsx +5 -18
  191. package/src/components/Menu.test.tsx +11 -17
  192. package/src/components/Menu.tsx +7 -27
  193. package/src/components/Popover.stories.tsx +4 -10
  194. package/src/components/Popover.tsx +3 -13
  195. package/src/components/Progress.tsx +5 -24
  196. package/src/components/ScrollArea.test.tsx +4 -6
  197. package/src/components/ScrollArea.tsx +10 -28
  198. package/src/components/Separator.test.tsx +2 -8
  199. package/src/components/Separator.tsx +1 -5
  200. package/src/components/Sidebar.stories.tsx +1 -5
  201. package/src/components/Sidebar.tsx +4 -22
  202. package/src/components/Spinner.tsx +1 -5
  203. package/src/components/Table.stories.tsx +1 -3
  204. package/src/components/Table.tsx +5 -30
  205. package/src/components/Text.stories.tsx +8 -13
  206. package/src/components/Text.tsx +1 -4
  207. package/src/components/Toast.test.tsx +6 -17
  208. package/src/components/Toast.tsx +4 -17
  209. package/src/components/Tooltip.stories.tsx +6 -28
  210. package/src/components/Tooltip.test.tsx +2 -8
  211. package/src/components/Tooltip.tsx +3 -12
  212. package/src/components/XStack.stories.tsx +4 -8
  213. package/src/components/XStack.test.tsx +9 -20
  214. package/src/components/XStack.tsx +2 -13
  215. package/src/components/YStack.stories.tsx +2 -8
  216. package/src/components/YStack.tsx +2 -13
  217. package/src/components/_internal/Story.tsx +6 -23
  218. package/src/components/_internal/VisuallyHiddenInput.tsx +4 -9
  219. package/src/components/_internal/dialog-styles.ts +1 -2
  220. package/src/components/_internal/layout.ts +1 -7
  221. package/src/components/_internal/separate.tsx +6 -9
  222. package/src/components/form/Checkbox.test.tsx +5 -16
  223. package/src/components/form/Checkbox.tsx +1 -4
  224. package/src/components/form/ColorPicker.stories.tsx +3 -10
  225. package/src/components/form/ColorPicker.test.tsx +1 -3
  226. package/src/components/form/ColorPicker.tsx +2 -6
  227. package/src/components/form/ColorPickerPrimitive.tsx +40 -151
  228. package/src/components/form/Combobox.stories.tsx +7 -31
  229. package/src/components/form/Combobox.test.tsx +10 -27
  230. package/src/components/form/Combobox.tsx +31 -89
  231. package/src/components/form/Form.context.ts +5 -19
  232. package/src/components/form/Form.stories.tsx +34 -23
  233. package/src/components/form/Form.test.tsx +105 -23
  234. package/src/components/form/Form.tsx +8 -0
  235. package/src/components/form/FormCheckbox.tsx +1 -5
  236. package/src/components/form/FormCombobox.tsx +4 -10
  237. package/src/components/form/FormField.tsx +50 -31
  238. package/src/components/form/FormGroupField.tsx +25 -0
  239. package/src/components/form/FormInput.tsx +2 -12
  240. package/src/components/form/FormInputGroup.tsx +3 -11
  241. package/src/components/form/FormSwitch.tsx +1 -5
  242. package/src/components/form/FormTextarea.tsx +3 -11
  243. package/src/components/form/Input.stories.tsx +1 -5
  244. package/src/components/form/Input.test.tsx +20 -31
  245. package/src/components/form/Input.tsx +1 -4
  246. package/src/components/form/InputGroup.stories.tsx +4 -23
  247. package/src/components/form/InputGroup.tsx +5 -10
  248. package/src/components/form/RadioGroup.test.tsx +14 -28
  249. package/src/components/form/RadioGroup.tsx +1 -5
  250. package/src/components/form/Select.stories.tsx +2 -10
  251. package/src/components/form/Select.test.tsx +4 -14
  252. package/src/components/form/Select.tsx +9 -38
  253. package/src/components/form/Slider.stories.tsx +7 -17
  254. package/src/components/form/Slider.test.tsx +4 -12
  255. package/src/components/form/Slider.tsx +4 -20
  256. package/src/components/form/Switch.test.tsx +3 -9
  257. package/src/components/form/Switch.tsx +2 -9
  258. package/src/components/form/Textarea.test.tsx +2 -6
  259. package/src/components/form/Textarea.tsx +1 -6
  260. package/src/entries/checkbox.ts +1 -4
  261. package/src/entries/form.ts +2 -0
  262. package/src/entries/group.ts +1 -5
  263. package/src/entries/radio-group.ts +1 -4
  264. package/src/lib/color.test.ts +2 -6
  265. package/src/lib/color.ts +3 -11
  266. package/src/lib/compose-refs.ts +1 -1
  267. package/src/public-api.test.ts +7 -8
@@ -11,14 +11,10 @@ type ComboboxChipProps = React.ComponentProps<typeof ComboboxPrimitive.Chip> & {
11
11
  classNames?: SlotClassNames<'remove'>;
12
12
  removeLabel?: string;
13
13
  };
14
- type ComboboxChipsInputProps = React.ComponentProps<
15
- typeof ComboboxPrimitive.Input
16
- >;
14
+ type ComboboxChipsInputProps = React.ComponentProps<typeof ComboboxPrimitive.Input>;
17
15
  type ComboboxChipsProps = React.ComponentProps<typeof ComboboxPrimitive.Chips>;
18
16
  type ComboboxClearProps = React.ComponentProps<typeof ComboboxPrimitive.Clear>;
19
- type ComboboxCollectionProps = React.ComponentProps<
20
- typeof ComboboxPrimitive.Collection
21
- >;
17
+ type ComboboxCollectionProps = React.ComponentProps<typeof ComboboxPrimitive.Collection>;
22
18
  type ComboboxContentProps = Pick<
23
19
  React.ComponentProps<typeof ComboboxPrimitive.Positioner>,
24
20
  'align' | 'anchor' | 'side' | 'sideOffset'
@@ -35,14 +31,9 @@ type ComboboxCreateItem = {
35
31
  value: string;
36
32
  };
37
33
  type ComboboxEmptyProps = React.ComponentProps<typeof ComboboxPrimitive.Empty>;
38
- type ComboboxGroupLabelProps = React.ComponentProps<
39
- typeof ComboboxPrimitive.GroupLabel
40
- >;
34
+ type ComboboxGroupLabelProps = React.ComponentProps<typeof ComboboxPrimitive.GroupLabel>;
41
35
  type ComboboxGroupProps = React.ComponentProps<typeof ComboboxPrimitive.Group>;
42
- type ComboboxInputProps = Omit<
43
- React.ComponentProps<typeof ComboboxPrimitive.Input>,
44
- 'size'
45
- > &
36
+ type ComboboxInputProps = Omit<React.ComponentProps<typeof ComboboxPrimitive.Input>, 'size'> &
46
37
  Pick<InputProps, 'size'> & {
47
38
  showClear?: boolean;
48
39
  showTrigger?: boolean;
@@ -74,15 +65,9 @@ type ComboboxProps<
74
65
  */
75
66
  onCreate?: (inputValue: string) => undefined | Value;
76
67
  };
77
- type ComboboxSeparatorProps = React.ComponentProps<
78
- typeof ComboboxPrimitive.Separator
79
- >;
80
- type ComboboxStatusProps = React.ComponentProps<
81
- typeof ComboboxPrimitive.Status
82
- >;
83
- type ComboboxTriggerProps = React.ComponentProps<
84
- typeof ComboboxPrimitive.Trigger
85
- >;
68
+ type ComboboxSeparatorProps = React.ComponentProps<typeof ComboboxPrimitive.Separator>;
69
+ type ComboboxStatusProps = React.ComponentProps<typeof ComboboxPrimitive.Status>;
70
+ type ComboboxTriggerProps = React.ComponentProps<typeof ComboboxPrimitive.Trigger>;
86
71
  type ComboboxValueProps = React.ComponentProps<typeof ComboboxPrimitive.Value>;
87
72
 
88
73
  const CREATE_ITEM = Symbol('pickle-ui.combobox.create');
@@ -90,9 +75,7 @@ const CREATE_ITEM = Symbol('pickle-ui.combobox.create');
90
75
  const EMPTY_VALUE: never[] = [];
91
76
 
92
77
  const ComboboxCreateLabelContext =
93
- React.createContext<(inputValue: string) => React.ReactNode>(
94
- defaultCreateLabel,
95
- );
78
+ React.createContext<(inputValue: string) => React.ReactNode>(defaultCreateLabel);
96
79
 
97
80
  const comboboxItemClassName =
98
81
  "data-highlighted:bg-accent data-highlighted:text-accent-foreground relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-none select-none data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4";
@@ -209,10 +192,7 @@ function ComboboxContent({
209
192
  );
210
193
  }
211
194
 
212
- function ComboboxCreatableRoot<
213
- Value,
214
- Multiple extends boolean | undefined = false,
215
- >({
195
+ function ComboboxCreatableRoot<Value, Multiple extends boolean | undefined = false>({
216
196
  createLabel = defaultCreateLabel,
217
197
  defaultValue,
218
198
  filter,
@@ -234,8 +214,7 @@ function ComboboxCreatableRoot<
234
214
  const [uncontrolledInputValue, setUncontrolledInputValue] = React.useState(
235
215
  String(props.defaultInputValue ?? ''),
236
216
  );
237
- const [uncontrolledValue, setUncontrolledValue] =
238
- React.useState(defaultValue);
217
+ const [uncontrolledValue, setUncontrolledValue] = React.useState(defaultValue);
239
218
  const query = String(inputValueProp ?? uncontrolledInputValue).trim();
240
219
  const value =
241
220
  valueProp !== undefined
@@ -243,7 +222,9 @@ function ComboboxCreatableRoot<
243
222
  : (uncontrolledValue ?? (props.multiple ? EMPTY_VALUE : null));
244
223
 
245
224
  const itemsWithCreate = React.useMemo(() => {
246
- if (!items || !query || hasItemLabel(items, query, itemToStringLabel)) {
225
+ // shortcut: a createItems() collection is opaque, so it gets no create
226
+ // item; support it if consumers pass one to a creatable Combobox.
227
+ if (!Array.isArray(items) || !query || hasItemLabel(items, query, itemToStringLabel)) {
247
228
  return items;
248
229
  }
249
230
 
@@ -276,10 +257,7 @@ function ComboboxCreatableRoot<
276
257
  return created === undefined ? [] : [created];
277
258
  };
278
259
 
279
- const handleValueChange: RootProps['onValueChange'] = (
280
- nextValue,
281
- eventDetails,
282
- ) => {
260
+ const handleValueChange: RootProps['onValueChange'] = (nextValue, eventDetails) => {
283
261
  let resolvedValue: unknown = nextValue;
284
262
 
285
263
  if (Array.isArray(nextValue)) {
@@ -294,11 +272,9 @@ function ComboboxCreatableRoot<
294
272
  resolvedValue = created;
295
273
  }
296
274
 
297
- const typedValue = resolvedValue as Parameters<
298
- NonNullable<RootProps['onValueChange']>
299
- >[0];
275
+ const typedValue = resolvedValue as Parameters<NonNullable<RootProps['onValueChange']>>[0];
300
276
 
301
- setUncontrolledValue(typedValue as RootProps['defaultValue']);
277
+ setUncontrolledValue(typedValue);
302
278
  onValueChange?.(typedValue, eventDetails);
303
279
  };
304
280
 
@@ -308,8 +284,7 @@ function ComboboxCreatableRoot<
308
284
  {...props}
309
285
  filter={
310
286
  filter &&
311
- ((item, filterQuery, toLabel) =>
312
- isCreateItem(item) || filter(item, filterQuery, toLabel))
287
+ ((item, filterQuery, toLabel) => isCreateItem(item) || filter(item, filterQuery, toLabel))
313
288
  }
314
289
  inputValue={inputValueProp}
315
290
  isItemEqualToValue={
@@ -322,13 +297,11 @@ function ComboboxCreatableRoot<
322
297
  items={itemsWithCreate}
323
298
  itemToStringLabel={
324
299
  itemToStringLabel &&
325
- ((item) =>
326
- isCreateItem(item) ? item.label : itemToStringLabel(item))
300
+ ((item) => (isCreateItem(item) ? item.label : itemToStringLabel(item)))
327
301
  }
328
302
  itemToStringValue={
329
303
  itemToStringValue &&
330
- ((item) =>
331
- isCreateItem(item) ? item.value : itemToStringValue(item))
304
+ ((item) => (isCreateItem(item) ? item.value : itemToStringValue(item)))
332
305
  }
333
306
  onInputValueChange={(nextInputValue, eventDetails) => {
334
307
  setUncontrolledInputValue(nextInputValue);
@@ -411,9 +384,7 @@ function ComboboxInput({
411
384
  <Input
412
385
  className={cn(
413
386
  showClear && showTrigger && '*:data-[slot=input]:pe-14',
414
- hasActions &&
415
- !(showClear && showTrigger) &&
416
- '*:data-[slot=input]:pe-8',
387
+ hasActions && !(showClear && showTrigger) && '*:data-[slot=input]:pe-8',
417
388
  )}
418
389
  nativeInput
419
390
  size={size}
@@ -434,12 +405,7 @@ function ComboboxInput({
434
405
  );
435
406
  }
436
407
 
437
- function ComboboxItem({
438
- children,
439
- className,
440
- classNames,
441
- ...props
442
- }: ComboboxItemProps) {
408
+ function ComboboxItem({ children, className, classNames, ...props }: ComboboxItemProps) {
443
409
  return (
444
410
  <ComboboxPrimitive.Item
445
411
  className={cn(comboboxItemClassName, className)}
@@ -479,10 +445,7 @@ function ComboboxList({ children, className, ...props }: ComboboxListProps) {
479
445
  {index > 0 ? <ComboboxSeparator /> : null}
480
446
  <ComboboxPrimitive.Collection>
481
447
  {(createItem: ComboboxCreateItem) => (
482
- <ComboboxCreateOption
483
- item={createItem}
484
- key={createItem.value}
485
- />
448
+ <ComboboxCreateOption item={createItem} key={createItem.value} />
486
449
  )}
487
450
  </ComboboxPrimitive.Collection>
488
451
  </ComboboxPrimitive.Group>
@@ -505,22 +468,13 @@ function ComboboxRoot<Value, Multiple extends boolean | undefined = false>({
505
468
  return <ComboboxPrimitive.Root {...props} />;
506
469
  }
507
470
 
508
- return (
509
- <ComboboxCreatableRoot
510
- createLabel={createLabel}
511
- onCreate={onCreate}
512
- {...props}
513
- />
514
- );
471
+ return <ComboboxCreatableRoot createLabel={createLabel} onCreate={onCreate} {...props} />;
515
472
  }
516
473
 
517
474
  function ComboboxSeparator({ className, ...props }: ComboboxSeparatorProps) {
518
475
  return (
519
476
  <ComboboxPrimitive.Separator
520
- className={cn(
521
- 'bg-border/50 pointer-events-none -mx-1 my-1 h-px',
522
- className,
523
- )}
477
+ className={cn('bg-border/50 pointer-events-none -mx-1 my-1 h-px', className)}
524
478
  data-slot="combobox-separator"
525
479
  {...props}
526
480
  />
@@ -530,21 +484,14 @@ function ComboboxSeparator({ className, ...props }: ComboboxSeparatorProps) {
530
484
  function ComboboxStatus({ className, ...props }: ComboboxStatusProps) {
531
485
  return (
532
486
  <ComboboxPrimitive.Status
533
- className={cn(
534
- 'text-muted-foreground px-3 py-2 text-sm empty:hidden',
535
- className,
536
- )}
487
+ className={cn('text-muted-foreground px-3 py-2 text-sm empty:hidden', className)}
537
488
  data-slot="combobox-status"
538
489
  {...props}
539
490
  />
540
491
  );
541
492
  }
542
493
 
543
- function ComboboxTrigger({
544
- children,
545
- className,
546
- ...props
547
- }: ComboboxTriggerProps) {
494
+ function ComboboxTrigger({ children, className, ...props }: ComboboxTriggerProps) {
548
495
  return (
549
496
  <ComboboxPrimitive.Trigger
550
497
  aria-label="Open popup"
@@ -567,16 +514,14 @@ function defaultCreateLabel(inputValue: string) {
567
514
 
568
515
  // Mirrors Base UI's label resolution so the create option only appears when
569
516
  // the typed text matches no existing item.
570
- function getItemLabel(
571
- item: unknown,
572
- itemToStringLabel?: (item: never) => string,
573
- ): string {
517
+ function getItemLabel(item: unknown, itemToStringLabel?: (item: never) => string): string {
574
518
  if (itemToStringLabel && item != null) {
575
519
  return itemToStringLabel(item as never) ?? '';
576
520
  }
577
521
 
578
522
  if (item && typeof item === 'object') {
579
523
  if ('label' in item && item.label != null) {
524
+ // eslint-disable-next-line typescript/no-base-to-string -- an item's label is a string or a number
580
525
  return String(item.label);
581
526
  }
582
527
 
@@ -585,6 +530,7 @@ function getItemLabel(
585
530
  }
586
531
  }
587
532
 
533
+ // eslint-disable-next-line typescript/no-base-to-string -- a primitive item, or an object without label or value
588
534
  return item == null ? '' : String(item);
589
535
  }
590
536
 
@@ -594,14 +540,10 @@ function hasItemLabel(
594
540
  itemToStringLabel?: (item: never) => string,
595
541
  ) {
596
542
  const normalizedQuery = query.toLocaleLowerCase();
597
- const flatItems = isGroupedItems(items)
598
- ? items.flatMap((group) => group.items)
599
- : items;
543
+ const flatItems = isGroupedItems(items) ? items.flatMap((group) => group.items) : items;
600
544
 
601
545
  return flatItems.some(
602
- (item) =>
603
- getItemLabel(item, itemToStringLabel).trim().toLocaleLowerCase() ===
604
- normalizedQuery,
546
+ (item) => getItemLabel(item, itemToStringLabel).trim().toLocaleLowerCase() === normalizedQuery,
605
547
  );
606
548
  }
607
549
 
@@ -1,9 +1,5 @@
1
1
  import * as React from 'react';
2
- import {
3
- useFormContext,
4
- type UseFormReturn,
5
- useFormState,
6
- } from 'react-hook-form';
2
+ import { useFormContext, type UseFormReturn, useFormState } from 'react-hook-form';
7
3
 
8
4
  type FormControlProps = {
9
5
  id?: string;
@@ -19,9 +15,7 @@ type WithoutAriaInvalid<Props> = Omit<Props, 'aria-invalid'> & {
19
15
  'aria-invalid'?: never;
20
16
  };
21
17
 
22
- const FormFieldContext = React.createContext<FormFieldContextValue | null>(
23
- null,
24
- );
18
+ const FormFieldContext = React.createContext<FormFieldContextValue | null>(null);
25
19
  const FormInputGroupContext = React.createContext(false);
26
20
 
27
21
  function getErrorMessage(error: unknown): React.ReactNode {
@@ -31,11 +25,7 @@ function getErrorMessage(error: unknown): React.ReactNode {
31
25
 
32
26
  const message = (error as { message?: unknown }).message;
33
27
 
34
- if (
35
- React.isValidElement(message) ||
36
- typeof message === 'string' ||
37
- typeof message === 'number'
38
- ) {
28
+ if (React.isValidElement(message) || typeof message === 'string' || typeof message === 'number') {
39
29
  return message;
40
30
  }
41
31
 
@@ -76,9 +66,7 @@ function useFormMethods() {
76
66
  const methods = useFormContext() as null | UseFormReturn;
77
67
 
78
68
  if (!methods) {
79
- throw new Error(
80
- 'Form components must be rendered inside <Form form={form}>.',
81
- );
69
+ throw new Error('Form components must be rendered inside <Form form={form}>.');
82
70
  }
83
71
 
84
72
  return methods;
@@ -88,9 +76,7 @@ function useRequiredFieldName(name: string | undefined, componentName: string) {
88
76
  const fieldName = useFieldName(name);
89
77
 
90
78
  if (!fieldName) {
91
- throw new Error(
92
- `${componentName} requires a name prop or a parent <Form.Field name="...">.`,
93
- );
79
+ throw new Error(`${componentName} requires a name prop or a parent <Form.Field name="...">.`);
94
80
  }
95
81
 
96
82
  return fieldName;
@@ -6,6 +6,7 @@ import { useForm } from 'react-hook-form';
6
6
  import { z } from 'zod/v4';
7
7
 
8
8
  import { Story } from '../_internal/Story';
9
+ import { Checkbox } from './Checkbox';
9
10
  import { Form } from './Form';
10
11
 
11
12
  const meta = {
@@ -96,26 +97,14 @@ function SignUpForm() {
96
97
  <Form.Input autoComplete="username" />
97
98
  </Form.Field>
98
99
 
99
- <Form.Field
100
- description="At least 8 characters."
101
- label="Password"
102
- name="password"
103
- >
100
+ <Form.Field description="At least 8 characters." label="Password" name="password">
104
101
  <Form.Input autoComplete="new-password" type="password" />
105
102
  </Form.Field>
106
103
 
107
104
  <Form.Field controlId="full-name" label="Full name">
108
105
  <Form.InputGroup>
109
- <Form.Input
110
- aria-label="First name"
111
- name="firstName"
112
- placeholder="First"
113
- />
114
- <Form.Input
115
- aria-label="Last name"
116
- name="lastName"
117
- placeholder="Last"
118
- />
106
+ <Form.Input aria-label="First name" name="firstName" placeholder="First" />
107
+ <Form.Input aria-label="Last name" name="lastName" placeholder="Last" />
119
108
  </Form.InputGroup>
120
109
  </Form.Field>
121
110
 
@@ -154,9 +143,7 @@ function SignUpForm() {
154
143
  {(value: Interest[]) => (
155
144
  <>
156
145
  {value.map((interest) => (
157
- <Form.Combobox.Chip key={interest.value}>
158
- {interest.label}
159
- </Form.Combobox.Chip>
146
+ <Form.Combobox.Chip key={interest.value}>{interest.label}</Form.Combobox.Chip>
160
147
  ))}
161
148
  <Form.Combobox.ChipsInput
162
149
  placeholder={value.length > 0 ? '' : 'Add interests…'}
@@ -177,11 +164,7 @@ function SignUpForm() {
177
164
  </Form.Combobox>
178
165
  </Form.Field>
179
166
 
180
- <Form.Field
181
- description="A sentence or two for your public profile."
182
- label="Bio"
183
- name="bio"
184
- >
167
+ <Form.Field description="A sentence or two for your public profile." label="Bio" name="bio">
185
168
  <Form.Textarea placeholder="Tell us about yourself" />
186
169
  </Form.Field>
187
170
 
@@ -224,3 +207,31 @@ export const SignUp: StoryDefinition = {
224
207
  </Story.Layout>
225
208
  ),
226
209
  };
210
+
211
+ const groceries = ['Flour', 'Eggs', 'Butter'];
212
+
213
+ function GroupFieldForm() {
214
+ const form = useForm<{ list: string[] }>({ defaultValues: { list: [] } });
215
+
216
+ return (
217
+ <Form form={form} onSubmit={() => {}}>
218
+ <Form.GroupField description="Each row keeps its own label." label="Grocery list" name="list">
219
+ {groceries.map((name) => (
220
+ <Form.GroupField.Item key={name}>
221
+ <Checkbox label={name} />
222
+ </Form.GroupField.Item>
223
+ ))}
224
+ </Form.GroupField>
225
+ </Form>
226
+ );
227
+ }
228
+
229
+ export const GroupField: StoryDefinition = {
230
+ render: () => (
231
+ <Story.Layout className="max-w-lg" title="Form">
232
+ <Story.Section title="List of rows">
233
+ <GroupFieldForm />
234
+ </Story.Section>
235
+ </Story.Layout>
236
+ ),
237
+ };
@@ -1,9 +1,11 @@
1
- import { fireEvent, render, screen, waitFor } from '@testing-library/react';
1
+ import { fireEvent, render, screen, waitFor, within } from '@testing-library/react';
2
2
  import * as React from 'react';
3
3
  import { useForm } from 'react-hook-form';
4
4
  import { describe, expect, it, vi } from 'vitest';
5
5
 
6
+ import { Checkbox } from './Checkbox';
6
7
  import { Form } from './Form';
8
+ import { RadioGroup } from './RadioGroup';
7
9
 
8
10
  type TestFormValues = {
9
11
  channel: string;
@@ -129,13 +131,8 @@ describe('Form', () => {
129
131
  it('displays field errors from React Hook Form state', async () => {
130
132
  render(<TestForm onSubmit={vi.fn()} withEmailError />);
131
133
 
132
- expect(
133
- await screen.findByText('Enter a valid email address.'),
134
- ).toBeInTheDocument();
135
- expect(screen.getByRole('textbox', { name: 'Email' })).toHaveAttribute(
136
- 'aria-invalid',
137
- 'true',
138
- );
134
+ expect(await screen.findByText('Enter a valid email address.')).toBeInTheDocument();
135
+ expect(screen.getByRole('textbox', { name: 'Email' })).toHaveAttribute('aria-invalid', 'true');
139
136
  });
140
137
 
141
138
  it('marks controlled boolean fields invalid from React Hook Form state', async () => {
@@ -149,15 +146,104 @@ describe('Form', () => {
149
146
  />,
150
147
  );
151
148
 
152
- expect(
153
- await screen.findByText('Choose a product update preference.'),
154
- ).toBeInTheDocument();
155
- expect(
156
- screen.getByRole('switch', { name: 'Product updates' }),
157
- ).toHaveAttribute('aria-invalid', 'true');
158
- expect(
159
- screen.getByRole('checkbox', { name: 'Accept terms' }),
160
- ).toHaveAttribute('aria-invalid', 'true');
149
+ expect(await screen.findByText('Choose a product update preference.')).toBeInTheDocument();
150
+ expect(screen.getByRole('switch', { name: 'Product updates' })).toHaveAttribute(
151
+ 'aria-invalid',
152
+ 'true',
153
+ );
154
+ expect(screen.getByRole('checkbox', { name: 'Accept terms' })).toHaveAttribute(
155
+ 'aria-invalid',
156
+ 'true',
157
+ );
158
+ });
159
+
160
+ describe('group fields', () => {
161
+ type ListFormValues = {
162
+ choices: string;
163
+ list: string[];
164
+ salt: boolean;
165
+ sugar: boolean;
166
+ };
167
+
168
+ function ListForm({ withErrors }: { withErrors?: boolean }) {
169
+ const form = useForm<ListFormValues>({
170
+ defaultValues: { choices: '', list: [], salt: false, sugar: false },
171
+ });
172
+
173
+ React.useEffect(() => {
174
+ if (withErrors) {
175
+ form.setError('list', { message: 'Pick one.', type: 'manual' });
176
+ form.setError('choices', { message: 'Choose.', type: 'manual' });
177
+ }
178
+ }, [form, withErrors]);
179
+
180
+ return (
181
+ <Form form={form} onSubmit={vi.fn()}>
182
+ <Form.GroupField label="Grocery list" name="list">
183
+ <div>
184
+ {['Flour', 'Eggs'].map((name) => (
185
+ <Form.GroupField.Item key={name}>
186
+ <Checkbox label={name} />
187
+ </Form.GroupField.Item>
188
+ ))}
189
+ {(['salt', 'sugar'] as const).map((name) => (
190
+ <Form.GroupField.Item key={name}>
191
+ <Form.Checkbox label={name} name={name} />
192
+ </Form.GroupField.Item>
193
+ ))}
194
+ </div>
195
+ </Form.GroupField>
196
+
197
+ <Form.GroupField label="Choices" name="choices">
198
+ {['Butter or margarine', 'Milk or cream'].map((name) => (
199
+ <Form.GroupField.Item key={name}>
200
+ <RadioGroup aria-label={name}>
201
+ <RadioGroup.Item label="First" value="first" />
202
+ <RadioGroup.Item label="Second" value="second" />
203
+ </RadioGroup>
204
+ </Form.GroupField.Item>
205
+ ))}
206
+ </Form.GroupField>
207
+ </Form>
208
+ );
209
+ }
210
+
211
+ it('names the list as a group and each row by its own label', () => {
212
+ render(<ListForm />);
213
+
214
+ const group = screen.getByRole('group', { name: 'Grocery list' });
215
+
216
+ expect(group).toHaveAttribute('data-slot', 'group-field');
217
+ const checkboxes = ['Flour', 'Eggs', 'salt', 'sugar'].map((name) =>
218
+ within(group).getByRole('checkbox', { name }),
219
+ );
220
+ const ids = checkboxes.map((checkbox) => checkbox.id);
221
+
222
+ expect(ids.every(Boolean)).toBe(true);
223
+ expect(new Set(ids).size).toBe(ids.length);
224
+ });
225
+
226
+ it('keeps the aria-label of each radio group', () => {
227
+ render(<ListForm />);
228
+
229
+ const group = screen.getByRole('group', { name: 'Choices' });
230
+
231
+ for (const name of ['Butter or margarine', 'Milk or cream']) {
232
+ expect(within(group).getByRole('radiogroup', { name })).toBeInTheDocument();
233
+ }
234
+ });
235
+
236
+ it('describes the rows with the field error', async () => {
237
+ render(<ListForm withErrors />);
238
+
239
+ expect(await screen.findByText('Pick one.')).toBeInTheDocument();
240
+ expect(screen.getByRole('checkbox', { name: 'Flour' })).toHaveAccessibleDescription(
241
+ 'Pick one.',
242
+ );
243
+ expect(screen.getByRole('radiogroup', { name: 'Milk or cream' })).toHaveAccessibleDescription(
244
+ 'Choose.',
245
+ );
246
+ });
161
247
  });
162
248
 
163
249
  describe('Form.Combobox', () => {
@@ -220,9 +306,7 @@ describe('Form', () => {
220
306
  {(value: Fruit[]) => (
221
307
  <>
222
308
  {value.map((tag) => (
223
- <Form.Combobox.Chip key={tag.value}>
224
- {tag.label}
225
- </Form.Combobox.Chip>
309
+ <Form.Combobox.Chip key={tag.value}>{tag.label}</Form.Combobox.Chip>
226
310
  ))}
227
311
  <Form.Combobox.ChipsInput />
228
312
  </>
@@ -263,9 +347,7 @@ describe('Form', () => {
263
347
  fireEvent.click(await screen.findByRole('option', { name: 'Banana' }));
264
348
 
265
349
  type('Tags', 'Kiwi');
266
- fireEvent.click(
267
- await screen.findByRole('option', { name: 'Create "Kiwi"' }),
268
- );
350
+ fireEvent.click(await screen.findByRole('option', { name: 'Create "Kiwi"' }));
269
351
 
270
352
  fireEvent.click(screen.getByRole('button', { name: 'Submit' }));
271
353
 
@@ -6,6 +6,11 @@ import { FormCombobox, type FormComboboxProps } from './FormCombobox';
6
6
  import { FormDescription, type FormDescriptionProps } from './FormDescription';
7
7
  import { FormError, type FormErrorProps } from './FormError';
8
8
  import { FormField, type FormFieldProps } from './FormField';
9
+ import {
10
+ FormGroupField,
11
+ type FormGroupFieldItemProps,
12
+ type FormGroupFieldProps,
13
+ } from './FormGroupField';
9
14
  import { FormInput, type FormInputProps } from './FormInput';
10
15
  import { FormInputGroup, type FormInputGroupProps } from './FormInputGroup';
11
16
  import { FormLabel, type FormLabelProps } from './FormLabel';
@@ -22,6 +27,7 @@ const Form = Object.assign(FormRoot, {
22
27
  Description: FormDescription,
23
28
  Error: FormError,
24
29
  Field: FormField,
30
+ GroupField: FormGroupField,
25
31
  Input: FormInput,
26
32
  InputGroup: FormInputGroup,
27
33
  Label: FormLabel,
@@ -38,6 +44,8 @@ export type {
38
44
  FormDescriptionProps,
39
45
  FormErrorProps,
40
46
  FormFieldProps,
47
+ FormGroupFieldItemProps,
48
+ FormGroupFieldProps,
41
49
  FormInputGroupProps,
42
50
  FormInputProps,
43
51
  FormLabelProps,
@@ -12,11 +12,7 @@ import {
12
12
 
13
13
  type FormCheckboxProps = WithoutAriaInvalid<CheckboxProps>;
14
14
 
15
- function FormCheckboxRoot({
16
- id: idProp,
17
- name: nameProp,
18
- ...props
19
- }: FormCheckboxProps) {
15
+ function FormCheckboxRoot({ id: idProp, name: nameProp, ...props }: FormCheckboxProps) {
20
16
  const { control } = useFormMethods();
21
17
  const name = useRequiredFieldName(nameProp, 'Form.Checkbox');
22
18
  const { field } = useController({
@@ -14,10 +14,9 @@ import {
14
14
  // Stable fallback so an unset multiple value keeps the same identity.
15
15
  const EMPTY_VALUE: never[] = [];
16
16
 
17
- type FormComboboxProps<
18
- Value,
19
- Multiple extends boolean | undefined = false,
20
- > = WithoutAriaInvalid<ComboboxProps<Value, Multiple>>;
17
+ type FormComboboxProps<Value, Multiple extends boolean | undefined = false> = WithoutAriaInvalid<
18
+ ComboboxProps<Value, Multiple>
19
+ >;
21
20
 
22
21
  function FormComboboxChipsInput({
23
22
  id: idProp,
@@ -83,10 +82,5 @@ const FormCombobox = Object.assign(FormComboboxRoot, {
83
82
  Value: Combobox.Value,
84
83
  });
85
84
 
86
- export {
87
- FormCombobox,
88
- FormComboboxChipsInput,
89
- FormComboboxInput,
90
- FormComboboxRoot,
91
- };
85
+ export { FormCombobox, FormComboboxChipsInput, FormComboboxInput, FormComboboxRoot };
92
86
  export type { FormComboboxProps };