brimdata / react-arborist

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

Deletion behavior can be unintuitive #231

Open kid-icarus opened 9 months ago

kid-icarus commented 9 months ago

Consider the following couple of screencaps of the cities demo

https://github.com/brimdata/react-arborist/assets/864752/5d16cd49-1a11-4062-9120-d1a63b062463

I select two items (Anderson and Andalusia), focus on a third (Allgood) item, and hit delete. The two selected items are deleted, yet the focused item is not, and the focus jumps to the next node after deleted nodes (Anniston). This feels jarring. Without having read the code, it wouldn't make sense to me what just happened or why.

Let's say you have some intuition behind that behavior that only the selected nodes will be deleted and the focused node will not. That intuition is correct if you've selected a single node. In this example, I select a single item (Anderson) and focus on the previous item (Andalusia). After hitting backspace, The focused item is deleted, rather than the selected item.

https://github.com/brimdata/react-arborist/assets/864752/efad6e71-29ca-4cf5-8914-331ba5aadb94

This unintuitive behavior can be avoided if you use the selectionFollowsFocus prop, but I thought I'd file an issue for consideration if we want to either change this default behavior, or allow a consumer to override the behvior.

jameskerr commented 8 months ago

Thank you for pointing this out. Yeah this could be improved. Like I mentioned in the other comment, the "delete" behavior will be overridable soon.

jameskerr commented 8 months ago

Also, it sounds like what is not intuitive is the "focus" behavior after delete. Is that right?

kid-icarus commented 8 months ago

Also, it sounds like what is not intuitive is the "focus" behavior after delete. Is that right?

Yeah exactly 👍🏻

kid-icarus commented 8 months ago

There's another thing to note, which is the difference in delete behavior when one item is selected, vs more than than one item selected. If more than one item is selected, the only items deleted are the selected items, and the focused item is ignored. If only a single item is selected, then the focused item is deleted, and selected item is not.