Skip to content
Prev Previous commit
Next Next commit
Document checkbox group migration
  • Loading branch information
mirka committed Sep 30, 2026
commit 08ef7c3efb83cfb8d4764b218686fdc6ffaa46ff
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import { CheckboxControl } from '@wordpress/ui';
| \`help\` | \`description\` | Use plain text only. |
| \`help\` with links or other markup | \`details\` | Use when the help text needs semantic content. |
| \`checked\` | \`checked\` | Continue passing the state for a controlled checkbox. |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we document the default form value change from "1" to "on" and show value="1" when preserving the legacy payload? A named checkbox migrated using these steps otherwise submits a different value.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, added in d1f6652.

| \`indeterminate\` | \`indeterminate\` | Continue passing the indeterminate state when needed. |
` }</Markdown>

## Labels
Expand All @@ -59,3 +58,33 @@ The new `CheckboxControl` requires a `label` prop with a plain `string` value. T
```

For a custom label layout, compose the [`Checkbox`](?path=/docs/design-system-components-form-primitives-checkbox--docs) and [`Field`](?path=/docs/design-system-components-form-primitives-field--docs) primitives.

## Checkbox groups

If a legacy checkbox uses `indeterminate` to show that only some items are selected, move the selected items into a `CheckboxGroup` instead of calculating the parent checkbox state yourself. Pass the child values to `allValues` and mark the select-all checkbox with `parent`. The group updates the parent checkbox when children change and selects or clears all children when the parent is clicked.

```jsx
import { useState } from '@wordpress/element';
import { CheckboxControl, CheckboxGroup } from '@wordpress/ui';

function FruitCheckboxes() {
const [ selectedFruits, setSelectedFruits ] = useState( [ 'apple' ] );

return (
<CheckboxGroup
value={ selectedFruits }
onValueChange={ setSelectedFruits }
allValues={ [ 'apple', 'orange' ] }
aria-label="Fruit"
>
<CheckboxControl parent value="fruit" label="Select all fruit" />
<CheckboxGroup.NestedItems>
<CheckboxControl value="apple" label="Apple" />
<CheckboxControl value="orange" label="Orange" />
</CheckboxGroup.NestedItems>
</CheckboxGroup>
);
}
```

See the [Checkbox Groups stories](?path=/docs/design-system-components-form-checkbox-groups--docs) for other grouping patterns.
Loading