Skip to content

Don't let users Tab to other elements when dragging #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/react-dnd-accessible-backend/KeyboardBackend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import type { AnnouncementMessages } from "./util/AnnouncementMessages";
const Trigger = {
DROP: [" ", "Enter"],
CANCEL_DRAG: ["Escape"],
TAB: ["Tab"],
};

function isTrigger(event: KeyboardEvent, trigger: typeof Trigger[keyof typeof Trigger]) {
Expand Down Expand Up @@ -112,6 +113,8 @@ export class KeyboardBackend implements Backend {
const sourceNode = this.sourceNodes.get(sourceId);
this._announcer.announceCancel(sourceNode ?? null, sourceId);
}
// Prevent tabbing to other elements when dragging locking the focus on drag source
if (this.monitor.isDragging() && isTrigger(event, Trigger.TAB)) event.preventDefault();
};

private setDndMode(enabled: boolean) {
Expand Down