giggles
Input

API Reference

API reference for the input system

useKeybindings()

Registers keybindings that only fire when the component is in the active focus path.

Type Signature
function useKeybindings(
  focus: { id: string },
  bindings: Keybindings,
  options?: KeybindingOptions
): void

Prop

Type

KeyHandler

Type Signature
type KeyHandler = (input: string, key: Key) => void

Prop

Type

Keybindings

Each value can be a plain handler function or a named binding object. Named bindings are registered in the command registry and become discoverable via useKeybindingRegistry.

Prop

Type

Key Names

Key stringTriggers on
up, down, left, rightArrow keys
enterReturn / Enter
escapeEscape
tabTab
shift+tabShift + Tab
backspaceBackspace or Delete (⌫)
deleteForward delete (⌦)
pageup, pagedownPage Up / Page Down
home, endHome / End
ctrl+c, ctrl+q, …Ctrl + any letter
a, j, ?, …Any printable character

KeybindingOptions

Prop

Type

When both fallback and named bindings are registered, dispatch follows this priority order:

PriorityWhat happens
1. Named binding matchesHandler fires, key stops
2. Key is in bubbleKey propagates to parent scope
3. fallback existsFallback handler fires
4. Nothing matchedKey propagates to parent scope

useKeybindingRegistry()

Reads named bindings registered across the app, filtered by scope. Returns bindings in three views depending on how broadly you want to look.

Type Signature
function useKeybindingRegistry(): KeybindingRegistry

Prop

Type

RegisteredKeybinding

Prop

Type

FocusTrap

Confines all keyboard input to its subtree. When mounted, keys no longer bubble past it — nothing outside the trap receives input. When unmounted, focus returns to the previously focused component.

Type Signature
function FocusTrap({ children }: {
  children: React.ReactNode;
}): JSX.Element

Prop

Type

On this page