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

Adding custom attribute/props to nodes

Open ciaoben opened this issue 6 years ago • 4 comments

Thanks for this great library. I am using it in a project where I need to click not only on the label of the node, but on the node itself (the <li class="rct-node"></li>) or at least being able to add custom attribute to each node so I can use data attribute and capture the click inside the node and use those attributes to trigger my logic.

Is there a way to do this? I want to avoid creating a fork of it considering that it is constantly maintained and improved.

ciaoben avatar Jun 12 '18 15:06 ciaoben

Currently there is no way to do this. May I ask what use case you have for clicking the entire node? Naturally, having something that records the click on the entire node itself would have it trigger if any child is also clicked. It would also trigger if you happen to click way away from the label, to the right, because of how the nodes fill up the remaining container space.

While I would not be entirely opposed to having custom attributes, there are so many DOM nodes that make up a checkbox node that it would not be practical to have a custom property area for every one of them (e.g. nodeAttributes, labelAttributes, checkboxAttributes, etc.).

jakezatecky avatar Jun 23 '18 20:06 jakezatecky

Thanks for the answer. Yeah, probably my use case is pretty specific and to be honest I am using this plugin to make the sidebar of a web application so it is not the use case you thought about when you design it.

Here is an example of my component based on yours: image

Right now to select a menu item, I need to click on the text. This behavior is not ideal as the user always try to click on the whole body of each item.

Probably will need to fork it and continue on a separate road considering that it is not the main use case for the library.

ciaoben avatar Jun 26 '18 06:06 ciaoben

@jakezatecky We need to allow users to tab through nodes. Any thoughts?

jonhill13 avatar Jan 10 '20 16:01 jonhill13

@jonhill13 The ability to tab through nodes is a feature I would like to add to this component eventually (likely part of #24). I could simply add a bunch of tabindex attributes to the resulting HTML nodes, but that would not be sufficient for full tab-based access.

I definitely would welcome a PR supporting tabbing through nodes, as it likely would have very little impact on other parts of the component.

jakezatecky avatar Jan 11 '20 00:01 jakezatecky