Skip to content

Checkbox

A yes-or-no choice saved with a form, and CheckboxGroup for several options that make one list. Use Switch for settings that apply at once.

Language
Appearance

With a description

Only about this appointment.
import { Checkbox } from '@arbol-ai/ui';

<Checkbox defaultSelected description="Only about this appointment.">
  Send reminders by WhatsApp
</Checkbox>

Group

Channels
We try them in this order.
import { Checkbox, CheckboxGroup } from '@arbol-ai/ui';

<CheckboxGroup defaultValue={['whatsapp']} description="We try them in this order." label="Channels">
  <Checkbox value="whatsapp">WhatsApp</Checkbox>
  <Checkbox value="voice">Phone call</Checkbox>
  <Checkbox value="email">Email</Checkbox>
</CheckboxGroup>

Select all

An indeterminate box says that only some are selected.

import { useState } from 'react';
import { Checkbox, CheckboxGroup } from '@arbol-ai/ui';

const CONTACTS = ['Ana Torres', 'Luis Gómez', 'Marta Ruiz'];

const SelectAllExample = () => {
  const [selected, setSelected] = useState(['Ana Torres']);
  return (
    <div className="grid gap-2">
      <Checkbox
        isIndeterminate={selected.length > 0 && selected.length < CONTACTS.length}
        isSelected={selected.length === CONTACTS.length}
        onChange={(isSelected) => {
          setSelected(isSelected ? CONTACTS : []);
        }}
      >
        All contacts
      </Checkbox>
      <CheckboxGroup aria-label="Contacts" className="ps-6" onChange={setSelected} value={selected}>
        {CONTACTS.map((contact) => (
          <Checkbox key={contact} value={contact}>
            {contact}
          </Checkbox>
        ))}
      </CheckboxGroup>
    </div>
  );
};

<SelectAllExample />

Source

The examples above are src/components/checkbox/checkbox.examples.tsx, which the library’s tests render too.

Type to search…

↑↓ navigate↵ selectEsc close