react-checkbox-tree
react-checkbox-tree copied to clipboard
How do I open a child node by default
When I open a project, I want its list of child nodes to be automatically expanded.
How do I set this?
That's the default expansion
You can set the expanded property to be an array of all of the parent node keys. There is currently no option to expand every available node, but that is a feature that is tracked in another issue slated for a later release.
Any updates ??
You can set an initial value for expanded to have the as many levels expanded as you want by utilizing expandNodesToLevel. E.g.:
import React, { useState } from 'react';
import CheckboxTree, { expandNodesToLevel } from 'react-checkbox-tree';
// Assuming `nodes` is accessible somewhere, this will open all parent nodes by default
const defaultExpanded = expandNodesToLevel(nodes, Infinity);
function Widget() {
const [expanded, setExpanded] = useState(defaultExpanded);
return <CheckboxTree nodes={nodes} expanded={expanded} />;
}