From 62f632a0c8f06ff020eb90d98770a374c705001d Mon Sep 17 00:00:00 2001 From: Clauderic Demers Date: Thu, 5 Dec 2024 11:51:13 -0500 Subject: [PATCH] End keyboard drag operation when pressing tab --- .changeset/end-on-tab.md | 5 +++++ packages/core/src/sensors/keyboard/defaults.ts | 2 +- packages/core/src/sensors/keyboard/types.ts | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 .changeset/end-on-tab.md diff --git a/.changeset/end-on-tab.md b/.changeset/end-on-tab.md new file mode 100644 index 00000000..08e118bc --- /dev/null +++ b/.changeset/end-on-tab.md @@ -0,0 +1,5 @@ +--- +'@dnd-kit/core': patch +--- + +Added `Tab` to the list of default key codes that end a drag and drop operation. Can be customized by passing in a custom list of `keyCodes` to the KeyboardSensor options. diff --git a/packages/core/src/sensors/keyboard/defaults.ts b/packages/core/src/sensors/keyboard/defaults.ts index ec469808..3026f102 100644 --- a/packages/core/src/sensors/keyboard/defaults.ts +++ b/packages/core/src/sensors/keyboard/defaults.ts @@ -3,7 +3,7 @@ import {KeyboardCoordinateGetter, KeyboardCode, KeyboardCodes} from './types'; export const defaultKeyboardCodes: KeyboardCodes = { start: [KeyboardCode.Space, KeyboardCode.Enter], cancel: [KeyboardCode.Esc], - end: [KeyboardCode.Space, KeyboardCode.Enter], + end: [KeyboardCode.Space, KeyboardCode.Enter, KeyboardCode.Tab], }; export const defaultKeyboardCoordinateGetter: KeyboardCoordinateGetter = ( diff --git a/packages/core/src/sensors/keyboard/types.ts b/packages/core/src/sensors/keyboard/types.ts index 635fdbda..1d0f29cd 100644 --- a/packages/core/src/sensors/keyboard/types.ts +++ b/packages/core/src/sensors/keyboard/types.ts @@ -9,6 +9,7 @@ export enum KeyboardCode { Up = 'ArrowUp', Esc = 'Escape', Enter = 'Enter', + Tab = 'Tab', } export type KeyboardCodes = {