Skip to content

Commit b7cee30

Browse files
committed
docs(Checkbox): restructure page to match component docs spec
Reorder sections to Usage → Anatomy → Examples → Recipes → Accessibility → FAQ, rewrite Form Integration recipe to correctly describe the auto-render behavior of Checkbox.Root's name prop, add Styling with Data Attributes recipe, and add a FAQ section.
1 parent 70a29bd commit b7cee30

File tree

1 file changed

+56
-31
lines changed

1 file changed

+56
-31
lines changed

apps/docs/src/pages/components/forms/checkbox.md

Lines changed: 56 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,12 @@ related:
1818

1919
# Checkbox
2020

21-
A headless checkbox component with dual-mode support: standalone boolean binding or group multi-selection with tri-state.
21+
A checkbox for boolean state or multi-selection groups with tri-state support.
2222

2323
<DocsPageFeatures :frontmatter />
2424

2525
## Usage
2626

27-
The Checkbox component supports two modes:
28-
29-
- **Standalone mode**: Use `v-model` on `Checkbox.Root` for simple boolean state
30-
- **Group mode**: Wrap in `Checkbox.Group` for multi-selection with array v-model
31-
3227
::: example
3328
/components/checkbox/basic
3429

@@ -82,11 +77,7 @@ A standalone checkbox with checkmark indicator and label.
8277
</template>
8378
```
8479

85-
## Recipes
86-
87-
### Group Mode
88-
89-
Wrap checkboxes in `Checkbox.Group` for multi-selection with array-based v-model:
80+
## Examples
9081

9182
::: example
9283
/components/checkbox/group
@@ -97,49 +88,63 @@ Multi-select checkbox group with three fruit options showing the selected state.
9788

9889
:::
9990

91+
::: example
92+
/components/checkbox/indeterminate
93+
94+
### Select All Pattern
95+
96+
A "select all" checkbox with tri-state behavior (checked, unchecked, indeterminate) over nested items.
97+
98+
:::
99+
100+
The `SelectAll` component:
101+
- Binds to the group's `isAllSelected` and `isMixed` state
102+
- Calls `toggleAll` on click
103+
- Does NOT register as a group item
104+
- Sets `aria-checked="mixed"` and `data-state="indeterminate"` when partially selected
105+
106+
## Recipes
107+
100108
### Form Integration
101109

102-
When the `name` prop is provided on `Checkbox.Root`, a hidden native checkbox is automatically rendered for form submission:
110+
Pass the `name` prop on `Checkbox.Root` and a hidden native checkbox is rendered automatically. No `Checkbox.HiddenInput` placement is required:
103111

104112
```vue
105113
<template>
106-
<!-- Auto-renders hidden input for form submission -->
107114
<Checkbox.Root name="agree" value="yes">
108115
<Checkbox.Indicator>✓</Checkbox.Indicator>
109116
</Checkbox.Root>
110117
</template>
111118
```
112119

113-
For custom form integration, use `Checkbox.HiddenInput` explicitly:
120+
Place `Checkbox.HiddenInput` explicitly only when you need to override the auto-rendered name, value, or form association:
114121

115122
```vue
116123
<template>
117-
<Checkbox.Root>
124+
<Checkbox.Root name="agree">
118125
<Checkbox.Indicator>✓</Checkbox.Indicator>
119126
120-
<Checkbox.HiddenInput name="custom" value="override" />
127+
<Checkbox.HiddenInput name="agree_override" value="custom" />
121128
</Checkbox.Root>
122129
</template>
123130
```
124131

125-
### Indeterminate State
126-
127-
Use `Checkbox.SelectAll` within a group for "select all" patterns. It automatically reflects the group's aggregate state and toggles all items on click:
132+
### Styling with Data Attributes
128133

129-
::: example
130-
/components/checkbox/indeterminate
134+
`Checkbox.Root` exposes data attributes for CSS styling without conditional classes:
131135

132-
### Indeterminate / Select All
136+
| Attribute | Values | Notes |
137+
|-----------|--------|-------|
138+
| `data-state` | `checked`, `unchecked`, `indeterminate` | Reflects current visual state |
139+
| `data-disabled` | `true` | Present only when disabled |
133140

134-
A "select all" checkbox with tri-state behavior (checked, unchecked, indeterminate) over nested items.
135-
136-
:::
137-
138-
The `SelectAll` component:
139-
- Binds to the group's `isAllSelected` and `isMixed` state
140-
- Calls `toggleAll` on click
141-
- Does NOT register as a group item
142-
- Sets `aria-checked="mixed"` and `data-state="indeterminate"` when partially selected
141+
```vue
142+
<template>
143+
<Checkbox.Root class="size-5 rounded border data-[state=checked]:bg-primary data-[disabled]:opacity-50">
144+
<Checkbox.Indicator>✓</Checkbox.Indicator>
145+
</Checkbox.Root>
146+
</template>
147+
```
143148

144149
## Accessibility
145150

@@ -164,4 +169,24 @@ For custom implementations, use `renderless` mode and bind the `attrs` slot prop
164169
</template>
165170
```
166171

172+
::: faq
173+
174+
??? How do I disable a checkbox?
175+
176+
Pass the `disabled` prop on `Checkbox.Root`. The component sets `aria-disabled`, removes `tabindex`, ignores click and Space key events, and exposes `data-disabled="true"` for styling.
177+
178+
??? Why does my form submission miss the checkbox value?
179+
180+
`Checkbox.Root` only renders the hidden native input when a `name` prop is set. Without `name`, the checkbox is purely visual and won't appear in `FormData`. Add `name="myField"` (and optionally `value`) to participate in form submission.
181+
182+
??? How does Checkbox.Group differ from a RadioGroup?
183+
184+
`Checkbox.Group` is a multi-selection container — its v-model is an array of selected values, and individual checkboxes can be in an indeterminate state via `Checkbox.SelectAll`. A radio group is single-selection — exactly one option is active and v-model holds a single value.
185+
186+
??? Can I use Checkbox.Root without the Indicator subcomponent?
187+
188+
Yes. `Checkbox.Indicator` is purely cosmetic — it reads checkbox state from context to render a checkmark. You can omit it entirely and render your own visual using the `attrs` slot prop on `Checkbox.Root`, or use `renderless` mode for full control over the rendered element.
189+
190+
:::
191+
167192
<DocsApi />

0 commit comments

Comments
 (0)