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

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/README.md CHANGED
@@ -193,6 +193,20 @@ export function SignUpForm() {
193
193
  }
194
194
  ```
195
195
 
196
+ A field whose content is not one control (a list of rows, a stepper, buttons)
197
+ goes in `Form.GroupField`: a group named by its label. Wrap each row's control in
198
+ `Form.GroupField.Item` so it keeps its own label and id.
199
+
200
+ ```tsx
201
+ <Form.GroupField label="Grocery list" name="list">
202
+ {ingredients.map((ingredient) => (
203
+ <Form.GroupField.Item key={ingredient.id}>
204
+ <Checkbox label={ingredient.name} />
205
+ </Form.GroupField.Item>
206
+ ))}
207
+ </Form.GroupField>
208
+ ```
209
+
196
210
  ## Theming
197
211
 
198
212
  Pickle is styled with Tailwind utilities that resolve to a small set of CSS
@@ -4,6 +4,7 @@ import { type FormComboboxProps } from './FormCombobox.js';
4
4
  import { FormDescription, type FormDescriptionProps } from './FormDescription.js';
5
5
  import { FormError, type FormErrorProps } from './FormError.js';
6
6
  import { FormField, type FormFieldProps } from './FormField.js';
7
+ import { type FormGroupFieldItemProps, type FormGroupFieldProps } from './FormGroupField.js';
7
8
  import { FormInput, type FormInputProps } from './FormInput.js';
8
9
  import { FormInputGroup, type FormInputGroupProps } from './FormInputGroup.js';
9
10
  import { FormLabel, type FormLabelProps } from './FormLabel.js';
@@ -38,6 +39,9 @@ declare const Form: typeof FormRoot & {
38
39
  Description: typeof FormDescription;
39
40
  Error: typeof FormError;
40
41
  Field: typeof FormField;
42
+ GroupField: ((props: FormGroupFieldProps) => import("react").JSX.Element) & {
43
+ Item: (props: FormGroupFieldItemProps) => import("react").JSX.Element;
44
+ };
41
45
  Input: typeof FormInput;
42
46
  InputGroup: typeof FormInputGroup;
43
47
  Label: typeof FormLabel;
@@ -64,5 +68,5 @@ declare const Form: typeof FormRoot & {
64
68
  Textarea: typeof FormTextarea;
65
69
  };
66
70
  export { Form };
67
- export type { FormCheckboxProps, FormComboboxProps, FormDescriptionProps, FormErrorProps, FormFieldProps, FormInputGroupProps, FormInputProps, FormLabelProps, FormProps, FormRadioGroupProps, FormSelectProps, FormSwitchProps, FormTextareaProps, };
71
+ export type { FormCheckboxProps, FormComboboxProps, FormDescriptionProps, FormErrorProps, FormFieldProps, FormGroupFieldItemProps, FormGroupFieldProps, FormInputGroupProps, FormInputProps, FormLabelProps, FormProps, FormRadioGroupProps, FormSelectProps, FormSwitchProps, FormTextareaProps, };
68
72
  //# sourceMappingURL=Form.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Form.d.ts","sourceRoot":"","sources":["../../../src/components/form/Form.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAgB,KAAK,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACtE,OAAO,EAAgB,KAAK,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,KAAK,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAC/E,OAAO,EAAE,SAAS,EAAE,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,KAAK,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC5E,OAAO,EAAE,SAAS,EAAE,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAkB,KAAK,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC5E,OAAO,EAAE,KAAK,SAAS,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EAAc,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EAA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,kBAAkB,CAAC;AAC5E,OAAO,EAAE,KAAK,SAAS,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EAAc,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EAAc,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,KAAK,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEtE,QAAA,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAmC4oB,CAAC;;;;;;;;;;;;;;;;;;CApBrpB,CAAC;AAEH,OAAO,EAAE,IAAI,EAAE,CAAC;AAChB,YAAY,EACV,iBAAiB,EACjB,iBAAiB,EACjB,oBAAoB,EACpB,cAAc,EACd,cAAc,EACd,uBAAuB,EACvB,mBAAmB,EACnB,mBAAmB,EACnB,cAAc,EACd,cAAc,EACd,SAAS,EACT,mBAAmB,EACnB,eAAe,EACf,eAAe,EACf,iBAAiB,GAClB,CAAC"}
@@ -5,6 +5,7 @@ import { FormCombobox } from './FormCombobox.js';
5
5
  import { FormDescription } from './FormDescription.js';
6
6
  import { FormError } from './FormError.js';
7
7
  import { FormField } from './FormField.js';
8
+ import { FormGroupField, } from './FormGroupField.js';
8
9
  import { FormInput } from './FormInput.js';
9
10
  import { FormInputGroup } from './FormInputGroup.js';
10
11
  import { FormLabel } from './FormLabel.js';
@@ -20,6 +21,7 @@ const Form = Object.assign(FormRoot, {
20
21
  Description: FormDescription,
21
22
  Error: FormError,
22
23
  Field: FormField,
24
+ GroupField: FormGroupField,
23
25
  Input: FormInput,
24
26
  InputGroup: FormInputGroup,
25
27
  Label: FormLabel,
@@ -1 +1 @@
1
- {"version":3,"file":"Form.js","sourceRoot":"","sources":["../../../src/components/form/Form.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,YAAY,EAA0B,MAA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ode;
9
9
  };
10
- declare function FormField({ children, className, controlId: controlIdProp, description, error, label, ...props }: FormFieldProps): React.JSX.Element;
11
- export { FormField };
10
+ declare function FormField(props: FormFieldProps): React.JSX.Element;
11
+ declare function FormFieldRoot({ children, className, controlId: controlIdProp, description, error, group, label, ...props }: FormFieldProps & {
12
+ group?: boolean;
13
+ }): React.JSX.Element;
14
+ export { FormField, FormFieldRoot };
12
15
  export type { FormFieldProps };
13
16
  //# sourceMappingURL=FormField.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FormField.d.ts","sourceRoot":"","sources":["../../../src/components/form/FormField.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC7C,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAe/B,KAAK,cAAc,GAAG,IAAI,CACxB,KAAK,CAAC,cAAc,CAAC,OAAO,KAAK,CAAC,IAAI,CAAC,EACvC,UAAU,CACX,GAAG;IACF,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC9B,KAAK,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACxB,KAAK,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CACzB,CAAC;AAEF,iBAAS,SAAS,CAAC,EACjB,QAAQ,EACR,SAAS,EACT,SAAS,EAAE,aAAa,EACxB,WAAW,EACX,KAAK,EACL,KAAK,EACL,GAAG,KAAK,EACT,EAAE,cAAc,qBAiDhB;AAoBD,OAAO,EAAE,SAAS,EAAE,CAAC;AACrB,YAAY,EAAE,cAAc,EAAE,CAAC"}
1
+ {"version":3,"file":"FormField.d.ts","sourceRoot":"","sources":["../../../src/components/form/FormField.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC7C,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAe/B,KAAK,cAAc,GAAG,IAAI,CACxB,KAAK,CAAC,cAAc,CAAC,OAAO,KAAK,CAAC,IAAI,CAAC,EACvC,UAAU,CACX,GAAG;IACF,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC9B,KAAK,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACxB,KAAK,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CACzB,CAAC;AAEF,iBAAS,SAAS,CAAC,KAAK,EAAE,cAAc,qBAEvC;AAyBD,iBAAS,aAAa,CAAC,EACrB,QAAQ,EACR,SAAS,EACT,SAAS,EAAE,aAAa,EACxB,WAAW,EACX,KAAK,EACL,KAAa,EACb,KAAK,EACL,GAAG,KAAK,EACT,EAAE,cAAc,GAAG;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,qBAmDtC;AAoBD,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,CAAC;AACpC,YAAY,EAAE,cAAc,EAAE,CAAC"}
@@ -10,7 +10,16 @@ import { FormError } from './FormError.js';
10
10
  import { FormLabel } from './FormLabel.js';
11
11
  import { FormRadioGroupRoot } from './FormRadioGroup.js';
12
12
  import { FormSelectRoot } from './FormSelect.js';
13
- function FormField({ children, className, controlId: controlIdProp, description, error, label, ...props }) {
13
+ function FormField(props) {
14
+ return _jsx(FormFieldRoot, { ...props });
15
+ }
16
+ // Native inputs use htmlFor/id for label focus; Base UI composites and groups
17
+ // use non-native labels so their primitives can wire aria-labelledby.
18
+ function FormFieldLabel({ children, controlId, id, native, }) {
19
+ return native ? (_jsx(FormLabel, { htmlFor: controlId, children: children })) : (_jsx(FormLabel, { id: id, nativeLabel: false, render: _jsx("span", {}), children: children }));
20
+ }
21
+ // Shared by Form.Field and Form.GroupField, which sets `group`.
22
+ function FormFieldRoot({ children, className, controlId: controlIdProp, description, error, group = false, label, ...props }) {
14
23
  const { control, getFieldState } = useFormMethods();
15
24
  const name = props.name;
16
25
  const formState = useFormState({
@@ -25,12 +34,14 @@ function FormField({ children, className, controlId: controlIdProp, description,
25
34
  // forms and rows.
26
35
  const generatedControlId = React.useId();
27
36
  const controlId = controlIdProp ?? generatedControlId;
28
- const nativeLabel = shouldUseNativeFieldLabel(children);
29
- const contextValue = React.useMemo(() => ({
30
- controlId,
31
- name,
32
- }), [controlId, name]);
33
- return (_jsxs(Field.Root, { className: cn('grid gap-2.5', className), "data-slot": "field", ...props, children: [label && nativeLabel ? (_jsx(FormLabel, { htmlFor: controlId, children: label })) : label ? (_jsx(FormLabel, { nativeLabel: false, render: _jsx("span", {}), children: label })) : null, _jsx(FormFieldContext.Provider, { value: contextValue, children: children }), errorMessage ? (_jsx(FormError, { match: true, children: errorMessage })) : description ? (_jsx(FormDescription, { children: description })) : null] }));
37
+ const labelId = React.useId();
38
+ const contextValue = React.useMemo(
39
+ // A group's rows each keep their own id.
40
+ () => ({ controlId: group ? undefined : controlId, name }), [controlId, group, name]);
41
+ return (_jsxs(Field.Root, { className: cn('grid gap-2.5', className), "data-slot": "field", ...(group && {
42
+ 'aria-labelledby': label ? labelId : undefined,
43
+ role: 'group',
44
+ }), ...props, children: [label ? (_jsx(FormFieldLabel, { controlId: controlId, id: labelId, native: !group && shouldUseNativeFieldLabel(children), children: label })) : null, _jsx(FormFieldContext.Provider, { value: contextValue, children: children }), errorMessage ? (_jsx(FormError, { match: true, children: errorMessage })) : description ? (_jsx(FormDescription, { children: description })) : null] }));
34
45
  }
35
46
  function isFormRadioGroupElement(child) {
36
47
  return React.isValidElement(child) && child.type === FormRadioGroupRoot;
@@ -41,5 +52,5 @@ function isFormSelectElement(child) {
41
52
  function shouldUseNativeFieldLabel(children) {
42
53
  return !React.Children.toArray(children).some((child) => isFormRadioGroupElement(child) || isFormSelectElement(child));
43
54
  }
44
- export { FormField };
55
+ export { FormField, FormFieldRoot };
45
56
  //# sourceMappingURL=FormField.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"FormField.js","sourceRoot":"","sources":["../../../src/components/form/FormField.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC7C,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAC;AACrC,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,cAAc,GACf,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAA4B,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAChF,OAAO,EAAwB,cAAc,EAAE,MAAM,cAAc,CAAC;AAapE,SAAS,SAAS,CAAC,EACjB,QAAQ,EACR,SAAS,EACT,SAAS,EAAE,aAAa,EACxB,WAAW,EACX,KAAK,EACL,KAAK,EACL,GAAG,KAAK,EACO;IACf,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,GAAG,cAAc,EAAE,CAAC;IACpD,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;IACxB,MAAM,SAAS,GAAG,YAAY,CAAC;QAC7B,OAAO;QACP,QAAQ,EAAE,CAAC,IAAI;QACf,KAAK,EAAE,IAAI;QACX,IAAI;KACL,CAAC,CAAC;IACH,MAAM,UAAU,GAAG,IAAI,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;IAC3E,MAAM,YAAY,GAAG,KAAK,IAAI,eAAe,CAAC,UAAU,CAAC,CAAC;IAC1D,2EAA2E;IAC3E,kBA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,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { Field } from '@base-ui/react/field';
2
+ import * as React from 'react';
3
+ import { type FormFieldProps } from './FormField.js';
4
+ type FormGroupFieldItemProps = React.ComponentProps<typeof Field.Item>;
5
+ type FormGroupFieldProps = Omit<FormFieldProps, 'controlId'>;
6
+ declare function FormGroupFieldItem(props: FormGroupFieldItemProps): React.JSX.Element;
7
+ declare function FormGroupFieldRoot(props: FormGroupFieldProps): React.JSX.Element;
8
+ declare const FormGroupField: typeof FormGroupFieldRoot & {
9
+ Item: typeof FormGroupFieldItem;
10
+ };
11
+ export { FormGroupField };
12
+ export type { FormGroupFieldItemProps, FormGroupFieldProps };
13
+ //# sourceMappingURL=FormGroupField.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FormGroupField.d.ts","sourceRoot":"","sources":["../../../src/components/form/FormGroupField.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC7C,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,KAAK,cAAc,EAAiB,MAAM,aAAa,CAAC;AAEjE,KAAK,uBAAuB,GAAG,KAAK,CAAC,cAAc,CAAC,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC;AACvE,KAAK,mBAAmB,GAAG,IAAI,CAAC,cAAc,EAAE,WAAW,CAAC,CAAC;AAG7D,iBAAS,kBAAkB,CAAC,KAAK,EAAE,uBAAuB,qBAEzD;AAID,iBAAS,kBAAkB,CAAC,KAAK,EAAE,mBAAmB,qBAErD;AAED,QAAA,MAAM,cAAc;;CAElB,CAAC;AAEH,OAAO,EAAE,cAAc,EAAE,CAAC;AAC1B,YAAY,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Field } from '@base-ui/react/field';
3
+ import { FormFieldRoot } from './FormField.js';
4
+ // One row: its control gets its own label and id instead of the field's.
5
+ function FormGroupFieldItem(props) {
6
+ return _jsx(Field.Item, { "data-slot": "group-field-item", ...props });
7
+ }
8
+ // A field whose content is not one control (a list of rows, a stepper,
9
+ // buttons): a group named by its label. Each row's control goes in an Item.
10
+ function FormGroupFieldRoot(props) {
11
+ return _jsx(FormFieldRoot, { "data-slot": "group-field", ...props, group: true });
12
+ }
13
+ const FormGroupField = Object.assign(FormGroupFieldRoot, {
14
+ Item: FormGroupFieldItem,
15
+ });
16
+ export { FormGroupField };
17
+ //# sourceMappingURL=FormGroupField.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FormGroupField.js","sourceRoot":"","sources":["../../../src/components/form/FormGroupField.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAG7C,OAAO,EAAuB,aAAa,EAAE,MAAM,aAAa,CAAC;AAKjE,yEAAyE;AACzE,SAAS,kBAAkB,CAAC,KAA8B;IACxD,OAAO,KAAC,KAAK,CAAC,IAAI,iBAAW,kBAAkB,KAAK,KAAK,GAAI,CAAC;AAChE,CAAC;AAED,uEAAuE;AACvE,4EAA4E;AAC5E,SAAS,kBAAkB,CAAC,KAA0B;IACpD,OAAO,KAAC,aAAa,iBAAW,aAAa,KAAK,KAAK,EAAE,KAAK,SAAG,CAAC;AACpE,CAAC;AAED,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE;IACvD,IAAI,EAAE,kBAAkB;CACzB,CAAC,CAAC;AAEH,OAAO,EAAE,cAAc,EAAE,CAAC"}
@@ -1,3 +1,3 @@
1
1
  export { Form } from '../components/form/Form.js';
2
- export type { FormCheckboxProps, FormComboboxProps, FormDescriptionProps, FormErrorProps, FormFieldProps, FormInputGroupProps, FormInputProps, FormLabelProps, FormProps, FormRadioGroupProps, FormSelectProps, FormSwitchProps, FormTextareaProps, } from '../components/form/Form.js';
2
+ export type { FormCheckboxProps, FormComboboxProps, FormDescriptionProps, FormErrorProps, FormFieldProps, FormGroupFieldItemProps, FormGroupFieldProps, FormInputGroupProps, FormInputProps, FormLabelProps, FormProps, FormRadioGroupProps, FormSelectProps, FormSwitchProps, FormTextareaProps, } from '../components/form/Form.js';
3
3
  //# sourceMappingURL=form.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../../src/entries/form.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAC/C,YAAY,EACV,iBAAiB,EACjB,iBAAiB,EACjB,oBAAoB,EACpB,cAAc,EACd,cAAc,EACd,mBAAmB,EACnB,cAAc,EACd,cAAc,EACd,SAAS,EACT,mBAAmB,EACnB,eAAe,EACf,eAAe,EACf,iBAAiB,GAClB,MAAM,yBAAyB,CAAC"}
1
+ {"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../../src/entries/form.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAC/C,YAAY,EACV,iBAAiB,EACjB,iBAAiB,EACjB,oBAAoB,EACpB,cAAc,EACd,cAAc,EACd,uBAAuB,EACvB,mBAAmB,EACnB,mBAAmB,EACnB,cAAc,EACd,cAAc,EACd,SAAS,EACT,mBAAmB,EACnB,eAAe,EACf,eAAe,EACf,iBAAiB,GAClB,MAAM,yBAAyB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pickle-ui/react",
3
- "version": "1.0.0-beta.13",
3
+ "version": "1.0.0-beta.14",
4
4
  "type": "module",
5
5
  "description": "React component library built with Base UI, shadcn/ui, Tailwind CSS, and reui.",
6
6
  "main": "dist/index.js",
@@ -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 = {
@@ -224,3 +225,35 @@ export const SignUp: StoryDefinition = {
224
225
  </Story.Layout>
225
226
  ),
226
227
  };
228
+
229
+ const groceries = ['Flour', 'Eggs', 'Butter'];
230
+
231
+ function GroupFieldForm() {
232
+ const form = useForm<{ list: string[] }>({ defaultValues: { list: [] } });
233
+
234
+ return (
235
+ <Form form={form} onSubmit={() => {}}>
236
+ <Form.GroupField
237
+ description="Each row keeps its own label."
238
+ label="Grocery list"
239
+ name="list"
240
+ >
241
+ {groceries.map((name) => (
242
+ <Form.GroupField.Item key={name}>
243
+ <Checkbox label={name} />
244
+ </Form.GroupField.Item>
245
+ ))}
246
+ </Form.GroupField>
247
+ </Form>
248
+ );
249
+ }
250
+
251
+ export const GroupField: StoryDefinition = {
252
+ render: () => (
253
+ <Story.Layout className="max-w-lg" title="Form">
254
+ <Story.Section title="List of rows">
255
+ <GroupFieldForm />
256
+ </Story.Section>
257
+ </Story.Layout>
258
+ ),
259
+ };
@@ -1,9 +1,17 @@
1
- import { fireEvent, render, screen, waitFor } from '@testing-library/react';
1
+ import {
2
+ fireEvent,
3
+ render,
4
+ screen,
5
+ waitFor,
6
+ within,
7
+ } from '@testing-library/react';
2
8
  import * as React from 'react';
3
9
  import { useForm } from 'react-hook-form';
4
10
  import { describe, expect, it, vi } from 'vitest';
5
11
 
12
+ import { Checkbox } from './Checkbox';
6
13
  import { Form } from './Form';
14
+ import { RadioGroup } from './RadioGroup';
7
15
 
8
16
  type TestFormValues = {
9
17
  channel: string;
@@ -160,6 +168,97 @@ describe('Form', () => {
160
168
  ).toHaveAttribute('aria-invalid', 'true');
161
169
  });
162
170
 
171
+ describe('group fields', () => {
172
+ type ListFormValues = {
173
+ choices: string;
174
+ list: string[];
175
+ salt: boolean;
176
+ sugar: boolean;
177
+ };
178
+
179
+ function ListForm({ withErrors }: { withErrors?: boolean }) {
180
+ const form = useForm<ListFormValues>({
181
+ defaultValues: { choices: '', list: [], salt: false, sugar: false },
182
+ });
183
+
184
+ React.useEffect(() => {
185
+ if (withErrors) {
186
+ form.setError('list', { message: 'Pick one.', type: 'manual' });
187
+ form.setError('choices', { message: 'Choose.', type: 'manual' });
188
+ }
189
+ }, [form, withErrors]);
190
+
191
+ return (
192
+ <Form form={form} onSubmit={vi.fn()}>
193
+ <Form.GroupField label="Grocery list" name="list">
194
+ <div>
195
+ {['Flour', 'Eggs'].map((name) => (
196
+ <Form.GroupField.Item key={name}>
197
+ <Checkbox label={name} />
198
+ </Form.GroupField.Item>
199
+ ))}
200
+ {(['salt', 'sugar'] as const).map((name) => (
201
+ <Form.GroupField.Item key={name}>
202
+ <Form.Checkbox label={name} name={name} />
203
+ </Form.GroupField.Item>
204
+ ))}
205
+ </div>
206
+ </Form.GroupField>
207
+
208
+ <Form.GroupField label="Choices" name="choices">
209
+ {['Butter or margarine', 'Milk or cream'].map((name) => (
210
+ <Form.GroupField.Item key={name}>
211
+ <RadioGroup aria-label={name}>
212
+ <RadioGroup.Item label="First" value="first" />
213
+ <RadioGroup.Item label="Second" value="second" />
214
+ </RadioGroup>
215
+ </Form.GroupField.Item>
216
+ ))}
217
+ </Form.GroupField>
218
+ </Form>
219
+ );
220
+ }
221
+
222
+ it('names the list as a group and each row by its own label', () => {
223
+ render(<ListForm />);
224
+
225
+ const group = screen.getByRole('group', { name: 'Grocery list' });
226
+
227
+ expect(group).toHaveAttribute('data-slot', 'group-field');
228
+ const checkboxes = ['Flour', 'Eggs', 'salt', 'sugar'].map((name) =>
229
+ within(group).getByRole('checkbox', { name }),
230
+ );
231
+ const ids = checkboxes.map((checkbox) => checkbox.id);
232
+
233
+ expect(ids.every(Boolean)).toBe(true);
234
+ expect(new Set(ids).size).toBe(ids.length);
235
+ });
236
+
237
+ it('keeps the aria-label of each radio group', () => {
238
+ render(<ListForm />);
239
+
240
+ const group = screen.getByRole('group', { name: 'Choices' });
241
+
242
+ for (const name of ['Butter or margarine', 'Milk or cream']) {
243
+ expect(
244
+ within(group).getByRole('radiogroup', { name }),
245
+ ).toBeInTheDocument();
246
+ }
247
+ });
248
+
249
+ it('describes the rows with the field error', async () => {
250
+ render(<ListForm withErrors />);
251
+
252
+ expect(await screen.findByText('Pick one.')).toBeInTheDocument();
253
+ expect(
254
+ screen.getByRole('checkbox', { name: 'Flour' }),
255
+ ).toHaveAccessibleDescription('Pick one.');
256
+ expect(
257
+ screen.getByRole('radiogroup', { name: 'Milk or cream' }),
258
+ ).toHaveAccessibleDescription('Choose.');
259
+ });
260
+ });
261
+
163
262
  describe('Form.Combobox', () => {
164
263
  type Fruit = { label: string; value: string };
165
264
  type FruitFormValues = { fruit: Fruit | null; tags: Fruit[] };
@@ -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,
@@ -27,15 +27,43 @@ type FormFieldProps = Omit<
27
27
  label?: React.ReactNode;
28
28
  };
29
29
 
30
- function FormField({
30
+ function FormField(props: FormFieldProps) {
31
+ return <FormFieldRoot {...props} />;
32
+ }
33
+
34
+ // Native inputs use htmlFor/id for label focus; Base UI composites and groups
35
+ // use non-native labels so their primitives can wire aria-labelledby.
36
+ function FormFieldLabel({
37
+ children,
38
+ controlId,
39
+ id,
40
+ native,
41
+ }: {
42
+ children: React.ReactNode;
43
+ controlId: string;
44
+ id: string;
45
+ native: boolean;
46
+ }) {
47
+ return native ? (
48
+ <FormLabel htmlFor={controlId}>{children}</FormLabel>
49
+ ) : (
50
+ <FormLabel id={id} nativeLabel={false} render={<span />}>
51
+ {children}
52
+ </FormLabel>
53
+ );
54
+ }
55
+
56
+ // Shared by Form.Field and Form.GroupField, which sets `group`.
57
+ function FormFieldRoot({
31
58
  children,
32
59
  className,
33
60
  controlId: controlIdProp,
34
61
  description,
35
62
  error,
63
+ group = false,
36
64
  label,
37
65
  ...props
38
- }: FormFieldProps) {
66
+ }: FormFieldProps & { group?: boolean }) {
39
67
  const { control, getFieldState } = useFormMethods();
40
68
  const name = props.name;
41
69
  const formState = useFormState({
@@ -50,29 +78,31 @@ function FormField({
50
78
  // forms and rows.
51
79
  const generatedControlId = React.useId();
52
80
  const controlId = controlIdProp ?? generatedControlId;
53
- const nativeLabel = shouldUseNativeFieldLabel(children);
81
+ const labelId = React.useId();
54
82
  const contextValue = React.useMemo(
55
- () => ({
56
- controlId,
57
- name,
58
- }),
59
- [controlId, name],
83
+ // A group's rows each keep their own id.
84
+ () => ({ controlId: group ? undefined : controlId, name }),
85
+ [controlId, group, name],
60
86
  );
61
87
 
62
88
  return (
63
89
  <Field.Root
64
90
  className={cn('grid gap-2.5', className)}
65
91
  data-slot="field"
92
+ {...(group && {
93
+ 'aria-labelledby': label ? labelId : undefined,
94
+ role: 'group',
95
+ })}
66
96
  {...props}
67
97
  >
68
- {/* Native inputs use htmlFor/id for label focus; Base UI composites
69
- use non-native labels so their primitives can wire aria-labelledby. */}
70
- {label && nativeLabel ? (
71
- <FormLabel htmlFor={controlId}>{label}</FormLabel>
72
- ) : label ? (
73
- <FormLabel nativeLabel={false} render={<span />}>
98
+ {label ? (
99
+ <FormFieldLabel
100
+ controlId={controlId}
101
+ id={labelId}
102
+ native={!group && shouldUseNativeFieldLabel(children)}
103
+ >
74
104
  {label}
75
- </FormLabel>
105
+ </FormFieldLabel>
76
106
  ) : null}
77
107
  <FormFieldContext.Provider value={contextValue}>
78
108
  {children}
@@ -104,5 +134,5 @@ function shouldUseNativeFieldLabel(children: React.ReactNode) {
104
134
  );
105
135
  }
106
136
 
107
- export { FormField };
137
+ export { FormField, FormFieldRoot };
108
138
  export type { FormFieldProps };
@@ -0,0 +1,25 @@
1
+ import { Field } from '@base-ui/react/field';
2
+ import * as React from 'react';
3
+
4
+ import { type FormFieldProps, FormFieldRoot } from './FormField';
5
+
6
+ type FormGroupFieldItemProps = React.ComponentProps<typeof Field.Item>;
7
+ type FormGroupFieldProps = Omit<FormFieldProps, 'controlId'>;
8
+
9
+ // One row: its control gets its own label and id instead of the field's.
10
+ function FormGroupFieldItem(props: FormGroupFieldItemProps) {
11
+ return <Field.Item data-slot="group-field-item" {...props} />;
12
+ }
13
+
14
+ // A field whose content is not one control (a list of rows, a stepper,
15
+ // buttons): a group named by its label. Each row's control goes in an Item.
16
+ function FormGroupFieldRoot(props: FormGroupFieldProps) {
17
+ return <FormFieldRoot data-slot="group-field" {...props} group />;
18
+ }
19
+
20
+ const FormGroupField = Object.assign(FormGroupFieldRoot, {
21
+ Item: FormGroupFieldItem,
22
+ });
23
+
24
+ export { FormGroupField };
25
+ export type { FormGroupFieldItemProps, FormGroupFieldProps };
@@ -5,6 +5,8 @@ export type {
5
5
  FormDescriptionProps,
6
6
  FormErrorProps,
7
7
  FormFieldProps,
8
+ FormGroupFieldItemProps,
9
+ FormGroupFieldProps,
8
10
  FormInputGroupProps,
9
11
  FormInputProps,
10
12
  FormLabelProps,