You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

react-checkbox-tree

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-checkbox-tree

React component for checkbox trees.

0.4.1
Source
npmnpm
Version published
Weekly downloads
232K
106.26%
Maintainers
1
Weekly downloads
 
Created
Source

react-checkbox-tree

npm Build Status Dependency Status devDependency Status GitHub license

Checkbox treeview for React.

Demo

Installation

The easiest way to use react-checkbox-tree is to install from NPM and include it in your own React build process (e.g. using Webpack):

npm install react-checkbox-tree --save

Note – This library requires that Font Awesome styles are loaded in the browser.

Usage

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() {
        const { checked, expanded } = this.state;

        return (
            <Tree
                nodes={nodes}
                checked={checked}
                expanded={expanded}
                onCheck={checked => this.setState({ checked }}
                onExpand={expanded => this.setState({ expanded }}
            />
        );
    }
}

Properties

PropertyTypeDescriptionDefault
nodesarrayRequired. Specifies the tree nodes and their children.
checkedarrayAn array of checked node values.[]
expandedarrayAn array of expanded node values.[]
onCheckfunctiononCheck handler: function(checked) {}() => {}
onExpandfunctiononExpand handler: function(expanded) {}() => {}
namestringOptional name for the hidden <input> element.undefined
nameAsArrayboolIf true, the hidden <input> will encode its values as an array rather than a joined string.false
optimisticToggleboolIf true, toggling a partially-checked node will select all children. If false, it will deselect.true

Keywords

react

FAQs

Package last updated on 16 Feb 2017

Did you know?

Socket

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.

Install

Related posts