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

Radio selections

Open parastooebrahimi opened this issue 4 years ago • 3 comments

I need this checkbox tree to be single select. is it possible?

parastooebrahimi avatar May 05 '20 03:05 parastooebrahimi

Can you elaborate on what you mean by single select?

jakezatecky avatar May 13 '20 22:05 jakezatecky

I guess I had the same need as you @parastooebrahimi You can hide checkboxes of parent node using the showCheckbox property on the nodes declaration. Like:

const nodes = [
  {
    label: 'parent node',
    value: 'parent1',
    showCheckbox: false,
    children: [...]
  },
  ...
];

Then you can force the tree to single select using:

function onNodeCheck(nodeIds, node) {
  if (singleSelect) {
    setChecked([node.value]);
  } else {
    setChecked(nodeIds);
  }
}

<CheckboxTree onCheck={ onNodeCheck } ... />

Hope it might help.

dpellier avatar May 18 '20 08:05 dpellier

@dpellier can you elaborate the solution?

SamdaniAnik avatar Feb 25 '22 04:02 SamdaniAnik