Checkbox
Turns an option on or off, or selects several items from a list, with an indeterminate state for partial selections.
Os revisores recebem o documento sem a minuta anterior.
<Checkbox description="Os revisores recebem o documento sem a minuta anterior." label="Enviar somente a versão final" />When to use
- To select zero or more items from a list: documents to download, rows in a table.
- For an option that is submitted with a form, such as “Notificar o revisor”.
- For a “select all” control that reflects a partial selection.
When not to use
- A setting that applies immediately. Use Switch.
- Choosing exactly one option. Use Radio group.
- Options that need a title and a description inside a card. Use Checkbox card.
States
A checkbox is unchecked, checked or indeterminate, and each can be disabled.
| State | Use for |
|---|---|
false |
The option is off. |
true |
The option is on. Shows a check. |
indeterminate |
Only some of the children are selected. Shows a minus. |
Examples
Label and description
Você pode desfazer isso nas configurações da tarefa.
Select all
The parent is indeterminate while only some children are selected. Selecting
it selects all children, and selecting it again clears them.
Without a label
Use it in table rows. Pass aria-label that names the row.
Content
- Write the label as the option, in affirmative form: “Notificar o revisor responsável”, not “Não notificar”.
- Keep labels short. Move the explanation to
description. - Label a select-all checkbox with what it selects: “Selecionar todos os documentos”.
Do and don’t
Accessibility
- Built on Radix Checkbox: a
buttonwithrole="checkbox".aria-checkedistrue,falseor"mixed"for the indeterminate state. Spacetoggles the checkbox.Tabmoves between checkboxes.- With
label, the label is linked byhtmlForandid, so clicking the text toggles the box. The id is generated when you do not pass one. - Without
label, passaria-label. A bare checkbox has no visible name. - The focus ring appears only for keyboard focus (
focus-visible). - Do not use color alone: the check and minus icons mark the state.
Code
import { Checkbox } from "@repo/ui/checkbox";
<Checkbox
checked={checked}
description="Os revisores recebem o documento sem a minuta anterior."
label="Enviar somente a versão final"
onCheckedChange={setChecked}
/>;
Props
Checkbox| Prop | Type | Default | Description |
|---|---|---|---|
checked | boolean | "indeterminate" | — | Controlled state: `true`, `false` or `"indeterminate"` (a mixed selection) |
description | string | — | Secondary text under the label |
disabled | boolean | false | Disables interaction and applies the disabled colors |
label | string | — | Visible label linked to the checkbox. Without it, pass `aria-label` |
labelProps | ComponentProps<typeof Typography> | — | Props forwarded to the label `Typography` |
onCheckedChange | (checked: boolean | "indeterminate") => void | — | Called with the new state when the user toggles |
required | boolean | false | Marks the field as required for forms and assistive tech |
Every other prop of the Radix Checkbox root, such as name, value and
defaultChecked, is forwarded.
Known issues
| Issue | Effect |
|---|---|
The box is size-4 (16px). The 32px hover halo is pointer-events-none, so it is not clickable. |
Below the 24px minimum hit target when the checkbox has no label, as in table rows. |
No style for aria-invalid. |
A checkbox cannot show a validation error, such as an unaccepted term. |
The focus ring uses ring-offset-background. The Tailwind config only defines old-background. |
The class generates nothing. The offset falls back to Tailwind’s default, white. |
label and description accept only string. |
A label with a link or formatted text needs a custom layout around CheckboxInput, which is not exported. |