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

Extend Node object

Open diegocamy opened this issue 3 years ago • 1 comments

Hi Jake, first of all, thank you for creating this library.

Is there a way to extend the Node object? I'm asking because I would like to have a path property.

What I did, that didn't work, was the following.

Created a file named react-checkbox-tree.d.ts in my types folder, and wrote the following

import { Node } from "react-checkbox-tree"

declare module "react-checkbox-tree" {
  interface Node {
    path: string
  }
}

I'm able to create a node using this interface but when I use the onClick function on my CheckboxTree component to console.log() the path, it shows undefined

<CheckboxTree
   nodes={nodes}
   noCascade
   expanded={expandedNodes}
   checked={checkedNodes}
   onExpand={(expanded) => setExpandedNodes(expanded)}
   onCheck={(checked) => setCheckedNodes(checked)}
   onClick={(node) => console.log(node.path)}
   showNodeIcon={false}
    />

Thank you!

diegocamy avatar Feb 11 '22 17:02 diegocamy

The library as written does not apply any additional extensions to the node objects. However, this is a straight-forward and reasonable enough use case that it can be a future enhancement.

jakezatecky avatar Feb 15 '22 22:02 jakezatecky