Skip to content

Commit

Permalink
Fix keyboard sensor activating when focusing elements within
Browse files Browse the repository at this point in the history
  • Loading branch information
clauderic committed Sep 19, 2024
1 parent 2c514fd commit fe76033
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/keyboard-sensor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@dnd-kit/dom': patch
---

Fixed a bug in the `KeyboardSensor` that would cause the sensor to activate when focusing elements within the sortable element other than the handle.
23 changes: 14 additions & 9 deletions packages/dom/src/core/sensors/keyboard/KeyboardSensor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,26 @@ export class KeyboardSensor extends Sensor<
return;
}

if (source.disabled || !source.element) {
if (source.disabled) {
return;
}

const {keyboardCodes = DEFAULT_KEYBOARD_CODES} = options ?? {};
if (
(!source.handle && source.element && event.target === source.element) ||
(source.handle && event.target === source.handle)
) {
const {keyboardCodes = DEFAULT_KEYBOARD_CODES} = options ?? {};

if (!keyboardCodes.start.includes(event.code)) {
return;
}
if (!keyboardCodes.start.includes(event.code)) {
return;
}

if (!this.manager.dragOperation.status.idle) {
return;
}
if (!this.manager.dragOperation.status.idle) {
return;
}

this.handleStart(event, source, options);
this.handleStart(event, source, options);
}
};

protected handleStart(
Expand Down

0 comments on commit fe76033

Please sign in to comment.