
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
react-checkbox-tree
Advanced tools
A simple and elegant checkbox tree for React.
Install the library using your favorite dependency manager:
yarn add react-checkbox-tree
Using npm:
npm install react-checkbox-tree --save
Note – This library makes use of Font Awesome styles and expects them to be loaded in the browser.
For your convenience, the library's styles can be consumed utilizing one of the following files:
node_modules/react-checkbox-tree/lib/react-checkbox-tree.css
node_modules/react-checkbox-tree/src/less/react-checkbox-tree.less
node_modules/react-checkbox-tree/src/scss/react-checkbox-tree.scss
Either include one of these files in your stylesheets or utilize a CSS loader:
import 'react-checkbox-tree/lib/react-checkbox-tree.css';
A quick usage example is included below. Note that the react-checkbox-tree component is controlled. In other words, it is stateless. You must update its checked
and expanded
properties whenever a change occurs.
import React from 'react';
import CheckboxTree from 'react-checkbox-tree';
const nodes = [{
value: 'mars',
label: 'Mars',
children: [
{ value: 'phobos', label: 'Phobos' },
{ value: 'deimos', label: 'Deimos' },
],
}];
class Widget extends React.Component {
constructor() {
super();
this.state = {
checked: [],
expanded: [],
};
}
render() {
return (
<CheckboxTree
nodes={nodes}
checked={this.state.checked}
expanded={this.state.expanded}
onCheck={checked => this.setState({ checked })}
onExpand={expanded => this.setState({ expanded })}
/>
);
}
}
All node objects must have a unique value
. This value is serialized into the checked
and expanded
arrays and is also used for performance optimizations.
Property | Type | Description | Default |
---|---|---|---|
nodes | array | Required. Specifies the tree nodes and their children. | |
checked | array | An array of checked node values. | [] |
expanded | array | An array of expanded node values. | [] |
name | string | Optional name for the hidden <input> element. | undefined |
nameAsArray | bool | If true, the hidden <input> will encode its values as an array rather than a joined string. | false |
noCascade | bool | If true, the toggling a parent will not cascade its check state to its children. | false |
optimisticToggle | bool | If true, toggling a partially-checked node will select all children. If false, it will deselect. | true |
showNodeIcon | bool | If true, each node will show a parent or leaf icon. | true |
onCheck | function | onCheck handler: function(checked) {} | () => {} |
onExpand | function | onExpand handler: function(expanded) {} | () => {} |
Individual nodes within the nodes
property can have the following structure:
Property | Type | Description |
---|---|---|
label | string | Required. The node's label. |
value | mixed | Required. The node's value. |
children | array | An array of child nodes. |
className | string | A className to add to the node. |
icon | mixed | A custom icon for the node. |
v0.6.2 (2017-05-25)
noCascade
option to decouple parent check state from childrenFAQs
A simple and elegant checkbox tree for React.
The npm package react-checkbox-tree receives a total of 114,070 weekly downloads. As such, react-checkbox-tree popularity was classified as popular.
We found that react-checkbox-tree demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.