shadcn.io is not affiliated with official shadcn/ui
Checkbox examples · Standard
Vertical List Checkbox for React
A stacked list of programming language checkboxes for picking any number of options.
The standard multi-select: one option per line. Five programming languages stack in a FieldGroup with gap-3, each a horizontal Field with its checkbox and label, mapped from a static list. Each box has its own name, so every checked language is submitted with the form. Use it for skills, features, permissions and any list where people weigh options one at a time.
Preview
Installation
FAQ
How do I adjust spacing between vertical checkboxes?
Change the gap-3 on the FieldGroup: gap-2 for a dense list, gap-4 or more for a relaxed form. The gap sits between the fields, so the first and last rows have no extra space.
How is each language wired to its checkbox?
A languages list maps to one horizontal Field per entry: JavaScript, TypeScript, Python, Java and C#. Each checkbox's name is the language id, so the checked ones are what the form submits.
The checkbox's id is the language id too, and the label's htmlFor points at it.
Are these checkboxes controlled?
No. None of them is given a checked value, so each box keeps its own state and the form reads them on submit. Hold the selected ids in state when something else on the page has to react to the choice.
Do vertical lists work on mobile?
Yes: one option per line is the layout that needs no adjusting on a narrow screen. Each label is clickable, so the whole row text is a tap target; raise the gap if rows sit too close for fingers.
How do I add a select-all box?
Put a parent checkbox above the list whose state is derived from the children: checked when all are, indeterminate when some are. The nested list shows the pattern.
Related
- Horizontal List CheckboxA row of weekday checkboxes that wraps
- Nested List CheckboxA select-all checkbox over three indented
- Right-Aligned CheckboxA list of notification settings with each
- Multiple Checkboxes FieldA fieldset of four checkboxes for the
- Simple CheckboxA checkbox with a label for a single
- Basic Radio GroupA vertical radio group of three options