No results found

Checklist

A group of selectable items that can be toggled individually or all at once.

Features

  • Select all/unselect all functionality
  • Mixed state handling for partial selections
  • Individual item selection tracking
  • WAI-ARIA checkbox list pattern
  • Form input integration
  • Dynamic item state synchronization
  • Nested accessibility descriptions per item
  • Independent item state management
  • Automated item indexing
  • Context-based state propagation

Anatomy

PartDescription
<Checklist.Root>—
<Checklist.Item>Internal prop for tracking item position in checklist
<Checklist.ItemLabel>—
<Checklist.ItemIndicator>—
<Checklist.ItemTrigger>—
<Checklist.ItemDescription>—
<Checklist.HiddenInput>The checklist hidden input manages multiple checkbox form inputs
<Checklist.ErrorMessage>—
<Checklist.SelectAll>—
<Checklist.SelectAllIndicator>—
<Checklist.Label>—

Examples

Basic Usage

The basic checklist setup allows users to select multiple items independently.

This example demonstrates:

Component State

Using Component State

The Checklist component provides a powerful way to manage multiple checkbox selections with a "select all" capability. Let's look at how to implement and control the checklist state. The basic checklist state is demonstrated in the hero example:

For more advanced state management, including a "select all" feature:

This example demonstrates:

State Interactions

The checklist maintains three main states:

  1. When clicking the select-all checkbox:
    • If unchecked: All items become checked
    • If checked or mixed: All items become unchecked
  2. When clicking individual items:
    • Updates the select-all checkbox state based on overall selection
    • Maintains the mixed state when appropriate The state management is handled automatically by the component, requiring no additional configuration from the user. Simply structure your checklist with the appropriate components and the state synchronization works out of the box.

Based on the provided implementation and examples, I'll document the configuration options for the Checklist component.

Core Configuration

Select All Behavior

The Checklist component supports a "select all" functionality that manages the state of all child checkboxes. As shown in the select-all example above, this requires configuring both the select all trigger and individual items. The select all state automatically manages three possible values:

Item Management

Items must be direct children of Checklist.Root to be properly tracked. The component internally manages indices for state synchronization.

Each Checklist.Item requires a unique key when mapping over items to maintain proper state tracking.

Group Configuration

The Checklist is configured as a checkbox group by default with the following characteristics:

type ChecklistContext = {
  isAllCheckedSig: Signal<boolean | "mixed">;
  checkedStatesSig: Signal<(boolean | "mixed")[]>;
};

The context manages:

Form Integration

The Checklist can be integrated with forms through the HiddenInput component. As shown in the hero example above, this manages the form submission state for all checkboxes in the group.

Advanced Configuration

State Synchronization

The Checklist implements a bi-directional state synchronization:

  1. Select All → Items:
  1. Items → Select All:

Custom Layouts

While the component handles state management, the layout is fully customizable. As shown in the select-all example above, items can be nested and grouped with custom spacing and hierarchies.

Note: The internal state tracking works regardless of DOM structure, but items must remain direct children of Checklist.Root in the component tree.

Based on the provided implementation and examples, I'll document the form-specific features of the Checklist component.

Forms

The Checklist component provides form integration through the <Checklist.HiddenInput> component, which manages multiple checkbox form inputs. The component follows a group pattern where the select-all functionality can control multiple checkbox states simultaneously.

In this example, the select-all checkbox controls the state of all child checkboxes, maintaining form state synchronization. When some items are selected, the select-all checkbox displays a mixed state, indicated by the minus icon. The form state is managed through the ChecklistContext, which tracks:

API Reference

Checklist Item

Props

PropTypeDefaultDescription
_indexnumber-

Checklist Root

Inherits from: <div />

Props

PropTypeDefaultDescription
_numItemsnumber-

Accessibility

Keyboard Interactions

KeyDescription
SpaceWhen focus is on a checkbox trigger (ChecklistItemTrigger or ChecklistSelectAll), toggles the checked state
EnterWhen focus is on a checkbox trigger (ChecklistItemTrigger or ChecklistSelectAll), toggles the checked state
TabMoves focus to the next checkbox trigger
Shift+TabMoves focus to the previous checkbox trigger