Skip to main content

Headless Tree provides its own implementation of keybindings that can be customized and extended.

Further down on this page, you can find a list of all available hotkeys. Note that the availability of hotkeys depends on the features that are included. For any hotkey to work, the hotkeysCoreFeature must be included. This enables some basic tree-related hotkeys like moving focus with arrow keys. Other feature-specific hotkeys, like toggling selection or renaming an item, need both the hotkeysCoreFeature and the feature that implements the functionality, such as the selectionFeature or the renamingFeature.

The type of a hotkey implementation is shown below. Read on to see how you can customize existing hotkeys with this type or add your own.

export interface HotkeyConfig<T> {
hotkey: string;
canRepeat?: boolean;
allowWhenInputFocused?: boolean;
isEnabled?: (tree: TreeInstance<T>) => boolean;
preventDefault?: boolean;
handler: (e: KeyboardEvent, tree: TreeInstance<T>) => void;
}

Overwriting Hotkeys

You can pass an object of partial hotkey implementations in the hotkeys config property to your tree. Default hotkeys and your custom hotkeys will be merged together during runtime, with your custom hotkeys overwriting the default hotkeys. This allows you to overwrite the keybindings, parts of the behavior (like being able to repeat pressing the key) certain hotkeys or overwriting their implementation.

Use the tables at the bottom of the page for reference of the hotkey names.

Adding custom Hotkeys

You can also very easily add custom hotkeys, with arbitrary keybindings and implementations. While you can technically use any names for the hotkeys, the TypeScript type is implemented to only support the official hotkey names and any names that are prefixed with custom to avoid mistakes.

Available Hotkeys

General Hotkeys

The following hotkeys need the hotkeysCoreFeature feature added.

KeyDefault KeybindingDescription
focusNextItemArrowDownFocuses the next item in the list.
focusPreviousItemArrowUpFocuses the previous item in the list.
expandOrDownArrowRightExpands the focused item if it is collapsed. If the focused item is already expanded, focuses the next item in the list.
collapseOrUpArrowLeftCollapses the focused item if it is expanded. If the focused item is already collapsed, focuses the previous item in the list.
focusFirstItemHomeFocuses the first item in the list.
focusLastItemEndFocuses the last item in the list.

Selections

The following hotkeys need the hotkeysCoreFeature and selectionFeature features added.

KeyDefault KeybindingDescription
toggleSelectedItemCtrl+SpaceToggles the selection of the focused item.
selectUpwardsShift+ArrowUpExpands the current selection by the item prior to the focused item, and moves focus upwards. Discards non-connected selection blocks.
selectDownwardsShift+ArrowDownExpands the current selection by the item after the focused item, and moves focus downwards. Discards non-connected selection blocks.
selectUpwardsCtrlCtrl+Shift+ArrowUpSame as selectUpwards, but doesn't discard other selection blocks.
selectDownwardsCtrlCtrl+Shift+ArrowDownSame as selectDownwards, but doesn't discard other selection blocks.
selectAllCtrl+ASelects all items in the list.

Drag And Drop

The following hotkeys need the hotkeysCoreFeature and dragAndDropFeature features added.

DnD Keybindings aren't implemented yet (TODO).

The following hotkeys need the hotkeysCoreFeature and searchFeature features added.

KeyDefault KeybindingDescription
openSearchLetterOrNumberOpens the search input and focuses it.
closeSearchEscapeCloses the search input.
submitSearchEnterSubmits the search input, and focuses and selects the last selected search result item.
nextSearchItemArrowDownFocuses the next search result item.
previousSearchItemArrowUpFocuses the previous search result item.

Renaming

The following hotkeys need the hotkeysCoreFeature and renamingFeature features added.

KeyDefault KeybindingDescription
renameItemF2Starts renaming the focused item.
abortRenameEscapeClose the rename input.
completeRenamingEnterClose the rename input, and call the config.onRename(item, newNameValue) config property.

Expand All

The following hotkeys need the hotkeysCoreFeature and expandAllFeature features added.

TODO not implemented yet.