react-accessible-treeview icon indicating copy to clipboard operation
react-accessible-treeview copied to clipboard

Batch propagated events

Open cmd-azalea opened this issue 9 months ago • 6 comments

Describe the solution you'd like When propagateSelect is on, selecting a parent node triggers onSelect (or some new prop) once instead of for the parent node and every child.

What value does this proposed solution bring to users? Right now there's no easy way to know when all onSelect events have been fired. You either have to manually track which selected node is the parent and keep track of which children have had their onSelect event fire, or check the treeState.selectedIds and then ignore each subsequent call to onSelect (this is also made more difficult by #190, and keeps us from using the element data). Neither of these solutions feel natural. This becomes a significant issue when running side effects based on tree selection that take time (for example, fetching data from a server).

Describe alternatives you've considered I've considered onNodeSelect since it would only trigger for the parent node, but it doesn't trigger if the node is selected programmatically. I've also used onBlur, but having to click outside the tree to apply changes makes for bad user experience and it again doesn't trigger for programmatic selections (i.e. a "select all" button).

cmd-azalea avatar Apr 22 '25 17:04 cmd-azalea

Hey @cmd-azalea, just have a question. You just want the selected ID that triggers it correct, not the propagated one. That should also contain the tree.selectedIds when it finished. You don't need to know which is propagated.

yhy-1 avatar Apr 30 '25 18:04 yhy-1

@yhy-1 The onSelect event contains more information; In my case I need the metadata of the selected or deselected nodes, not just their IDs. I can get that data fine right now, but the problem is there's no way of knowing when the propagation ends. In my case, I'm using the tree to set filters for some data fetching. I need a way to know when all of the onSelect events have fired so that I can make my web call to get the new filtered data. Right now I'm doing it based on onBlur, but it would be nice to not make the users click out of the tree before the filters are applied.

cmd-azalea avatar May 16 '25 19:05 cmd-azalea

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jul 15 '25 20:07 stale[bot]

This issue was closed automatically since it was marked as stale because it has not had recent activity. Thank you for your contributions.

stale[bot] avatar Jul 25 '25 04:07 stale[bot]

Hey @dgreene1 I would gladly work on it, if you don't mind.

dolgachio avatar Nov 28 '25 17:11 dolgachio

That would be wonderful, thank you! Our contribution requirements include unit tests please.

dgreene1 avatar Nov 28 '25 18:11 dgreene1