View fulldotdev/ui on GitHub

Checkbox

A control that allows the user to toggle between checked and not checked.

Installation

npx shadcn@latest add @fulldev/checkbox

Usage

import { Checkbox } from "@/components/ui/checkbox"
<Checkbox />

Checkbox renders a native input type="checkbox" and accepts its attributes, so it submits with a form and works without JavaScript.

Checked State

Use the native checked attribute for the initial state. Read or set input.checked and listen to the native change event to react to changes. Set input.indeterminate = true in a script for the indeterminate state.

Invalid State

Set aria-invalid="true" on the checkbox and data-invalid on the field wrapper to show the invalid styles.

Basic

Pair the checkbox with Field and FieldLabel for proper layout and labeling.

Description

Use FieldContent and FieldDescription for helper text.

Disabled

Use the disabled attribute to prevent interaction and add data-disabled to the Field for disabled styles.

Group

Use multiple fields to create a checkbox list.

Table

RTL

API Reference

Source: src/components/ui/checkbox

Checkbox accepts every input attribute except type, such as checked, disabled, required, name, value and aria-invalid.