-
Notifications
You must be signed in to change notification settings - Fork 179
Description
When performing multi-selection with the mouse, the expected behavior (familiar from applications like Windows File Explorer) is to use CTRL + Click to select multiple items.
Currently, react-arborist uses e.metaKey to detect multi-selection, which is standard on macOS but not Windows. This results in an inconsistent user experience on Windows.
Current Behavior
The relevant code can be found here:
react-arborist/modules/react-arborist/src/interfaces/node-api.ts
Lines 199 to 208 in c851c6f
| handleClick = (e: React.MouseEvent) => { | |
| if (e.metaKey && !this.tree.props.disableMultiSelection) { | |
| this.isSelected ? this.deselect() : this.selectMulti(); | |
| } else if (e.shiftKey && !this.tree.props.disableMultiSelection) { | |
| this.selectContiguous(); | |
| } else { | |
| this.select(); | |
| this.activate(); | |
| } | |
| }; |
Expected Behavior
The following diff demonstrates how to modify the handleClick function to correctly handle multi-selection on both macOS and Windows by checking for either e.metaKey (Cmd on macOS) or e.ctrlKey (Ctrl on Windows):
handleClick = (e: React.MouseEvent) => {
- if (e.metaKey && !this.tree.props.disableMultiSelection) {
+ if ((e.metaKey || e.ctrlKey) && !this.tree.props.disableMultiSelection) {
this.isSelected ? this.deselect() : this.selectMulti();
} else if (e.shiftKey && !this.tree.props.disableMultiSelection) {
this.selectContiguous();
} else {
this.select();
this.activate();
}
};Alternative Solution
An alternative, more flexible solution would be to allow users to customize the selection shortcuts.
I support the proposition made in #57. While this approach is more involved, it provides greater flexibility.
The proposed change in this issue offers a quick fix for the common Windows use case.