Skip to main content

Overview

The Keyboard sensor enables keyboard-based drag and drop interactions. It is enabled by default in the DragDropManager.

Usage

Default Key Bindings

The Keyboard sensor comes with these default key bindings:

Customizing Key Bindings

You can customize which keys trigger different actions:
Key bindings are matched against KeyboardEvent.key, so they respect keyboard layouts and operating system key remaps. Use KeyboardEvent.key values such as w, Enter, and ArrowUp. The Space alias is also supported for the Space key. If you are migrating a configuration that used KeyboardEvent.code, common Key* and Digit* values such as KeyW and Digit1 are normalized for compatibility. Other physical key codes, such as NumpadEnter, BracketLeft, or Slash, should be replaced with the key value they produce. Other named keys must match KeyboardEvent.key casing.

Default behavior

By default, each arrow key press moves the dragged item by 10 pixels. Hold Shift to multiply movement by 5 (so 50 pixels with the default offset).

API Reference

Options

KeyboardCodes
Configure which keyboard keys trigger different actions:
number | {x: number; y: number}
default:"10"
The number of pixels to move the dragged item per arrow key press. Pass a single number to apply equally to both axes, or an object to set per-axis values. Hold Shift while pressing an arrow key to multiply this offset by 5.
(event: KeyboardEvent, source: Draggable) => boolean
Return true to prevent the sensor from starting a drag for a given keydown event. By default, the sensor only activates when the keyboard event’s target is the draggable’s handle (or its element if no handle is set) — preventing accidental drags from focused descendants like buttons or inputs.

Events

The Keyboard sensor handles these events:
  • keydown: Key press detection
  • keyup: Key release detection

Activation

The sensor activates when:
  1. A draggable element or its handle has focus
  2. A configured start key is pressed
  3. The element isn’t disabled

Best Practices

  1. Provide clear focus indicators:
    • Use visible focus rings
    • Maintain sufficient contrast
  2. Support screen readers:
    • Use proper ARIA attributes
    • Provide clear instructions
  3. Consider key combinations:
    • Avoid conflicts with browser shortcuts
    • Support standard keyboard patterns