React Checkbox Tree

2.0.1 · active · verified Sun Apr 19

react-checkbox-tree is a React component designed to render a hierarchical tree of checkboxes. It provides a simple and elegant solution for implementing multi-select functionality with nested options. Currently stable at version 2.0.1, released in April 2026, the library recently underwent a major accessibility-focused overhaul in its 2.0.0 release. While its release cadence has historically varied, with a significant gap before the v2.x releases, the recent activity suggests ongoing development. Key differentiators include its controlled component architecture, support for customizable icons (including Font Awesome v4, v5, and v6), robust accessibility features, and strict enforcement of unique node values to optimize performance for internal state management.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to integrate `react-checkbox-tree` into a React application, managing its controlled `checked` and `expanded` states using React hooks. It also shows the necessary CSS import and basic node definition.

import React, { useState } from 'react';
import CheckboxTree from 'react-checkbox-tree';
import 'react-checkbox-tree/lib/react-checkbox-tree.css';

const nodes = [
  {
    value: 'grand-parent',
    label: 'Grand Parent',
    children: [
      { value: 'parent-1', label: 'Parent 1',
        children: [
          { value: 'child-1a', label: 'Child 1a' },
          { value: 'child-1b', label: 'Child 1b' },
        ],
      },
      { value: 'parent-2', label: 'Parent 2' },
    ],
  },
  { value: 'single-node', label: 'A Standalone Node' }
];

function MyCheckboxTreeWidget() {
  // State for checked nodes, initialized as an empty array
  const [checked, setChecked] = useState<string[]>([]);
  // State for expanded nodes, initialized as an empty array
  const [expanded, setExpanded] = useState<string[]>([]);

  return (
    <div style={{ padding: '20px', maxWidth: '400px', border: '1px solid #eee', borderRadius: '5px' }}>
      <h2>Hierarchical Selection</h2>
      <p>Selected items: <strong>{checked.length > 0 ? checked.join(', ') : 'None'}</strong></p>
      <CheckboxTree
        nodes={nodes}
        checked={checked}
        expanded={expanded}
        onCheck={(checkedList) => setChecked(checkedList)}
        onExpand={(expandedList) => setExpanded(expandedList)}
        showExpandAll={true}
        showNodeIcon={false}
      />
    </div>
  );
}

export default MyCheckboxTreeWidget;

// To use this in your App.tsx or App.jsx:
// import MyCheckboxTreeWidget from './MyCheckboxTreeWidget';
// function App() {
//   return <MyCheckboxTreeWidget />;
// }

view raw JSON →