Skip to content

ListView Drag and Drop "link" behavior using Ctrl or Alt as modifier key does not work with keyboardΒ #4218

Open
@majornista

Description

@majornista

πŸ› Bug Report

Using the ListView Drag and Drop -- draggable rows allow copy and link Storybook Story, after selecting an item to drag using the keyboard and moving keyboard focus the drop target, try to drop as a link using Alt+Enter on Windows/Control+Enter on macOS keyboard combination.

πŸ€” Expected Behavior

Drag and Drop should fire events to complete a dropOperation: "link" on the drop target onDrop, dragEnd, onDropExit.

😯 Current Behavior

Drag and Drop only allows copy or cancel drop operations, Alt+Enter triggers the DragSession.activate() method, while Ctrl+Enter triggers a copy drop operation rather than a link.

πŸ’ Possible Solution

We need to determine the allowed drop operations when the Enter key is pressed using a modifier on a drop target, here:

onKeyDown(e: KeyboardEvent) {
this.cancelEvent(e);
if (e.key === 'Escape') {
this.cancel();
return;
}
if (e.key === 'Tab' && !(e.metaKey || e.altKey || e.ctrlKey)) {
if (e.shiftKey) {
this.previous();
} else {
this.next();
}
}
if (typeof this.currentDropTarget?.onKeyDown === 'function') {
this.currentDropTarget.onKeyDown(e, this.dragTarget);
}
}
onKeyUp(e: KeyboardEvent) {
this.cancelEvent(e);
if (e.key === 'Enter') {
if (e.altKey) {
this.activate();
} else {
this.drop();
}
}
}

πŸ”¦ Context

FY23 Accessibility Audit

πŸ’» Code Sample

🌍 Your Environment

Software Version(s)
react-spectrum @adobe/[email protected]
Browser Chrome Version 111.0.5563.64 (Official Build) (arm64)
Operating System macOS Ventura 13.2.1 (22D68)

🧒 Your Company/Team

πŸ•· Tracking Issue (optional)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    🩺 To Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions