shadcn.io is not affiliated with official shadcn/ui
Checkbox examples · Standard
Disabled Checkbox for React
Two disabled checkboxes, one unchecked and one checked, for options people can see but not change.
Sometimes an option should be visible but out of reach. This example shows both disabled states: an empty box and a checked one. The checkbox is disabled, and data-disabled on each Field fades the label with the box, so the whole row reads as unavailable and clicks do nothing. Use it for features a plan doesn't include, read-only views of saved settings, or options that depend on another choice.
Preview
Installation
FAQ
When should I disable checkboxes instead of hiding them?
Disable an option people should know exists but can't use right now: a feature on a higher plan, a choice that needs another one first, a setting that's locked. Hide it when it doesn't apply to them at all. Either way, say why nearby when it isn't obvious.
How do I show a disabled checkbox as checked?
Start it checked and disable it, as the second row does. It reads as "this is on and can't be changed", for included features or requirements already met.
Pass defaultChecked (or a controlled checked) together with disabled.
Why does the label fade too?
data-disabled on the Field dims its label to match the box. A faded box next to full-strength text looks like a bug; dimming the whole row says the entire option is unavailable.
How do I conditionally disable checkboxes based on other form state?
Compute the disabled flag from your state and pass it on every render, for example when a parent option is off or a selection limit is reached. Put the same condition on the field's data-disabled, and add a line of helper text such as "Select up to 3" so people know why.
Related
- Simple CheckboxA checkbox with a label for a single
- Indeterminate CheckboxA checkbox that starts indeterminate, the
- Todo Style CheckboxA to-do item whose label is struck
- Vertical List CheckboxA stacked list of programming language
- Disabled SwitchA disabled switch that shows its state
- Radio Group with Disabled StatesThree radio groups compared: all enabled