react-checkbox-tree icon indicating copy to clipboard operation
react-checkbox-tree copied to clipboard

How do I open a child node by default

Open GHzhuzhu opened this issue 4 years ago • 1 comments

When I open a project, I want its list of child nodes to be automatically expanded. How do I set this? image That's the default expansion

GHzhuzhu avatar Aug 07 '21 04:08 GHzhuzhu

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.

jakezatecky avatar Aug 08 '21 02:08 jakezatecky

Any updates ??

munishchoudhary204 avatar Dec 16 '22 14:12 munishchoudhary204

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} />;
}

jakezatecky avatar Mar 15 '23 19:03 jakezatecky