brimdata / react-arborist

The complete tree view component for React
MIT License
3.06k stars 139 forks source link

Selecting parent node checkbox as intermediate #173

Open anupsingh244 opened 1 year ago

anupsingh244 commented 1 year ago

I want to make parent node checkbox as intermediate selection on the selection of child nodes? I dont see any way to do it. can you please help me with that.

jameskerr commented 1 year ago

I would imagine in your node renderer, you could run a check that looks through all the children in the node to see if they are selected. If some but not all are selected, you could add a class to the component that marks it as intermediate.

const allSelected = node.children.every((child) => child.isSelected)
const someSelected = node.children.some((child) => child.isSelected)

if (someSelected && !allSelected) {
  // Add your intermediate style
}

If this works for you, will you please close the issue. Thank you and good luck!