Skip to content

Windows: Multi-select should use Ctrl+Click, not Meta+Click #303

@CodyAdam

Description

@CodyAdam

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:

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions