Skip to content

KeyboardCommand

A keyboard command shown in a modal’s control strip and optionally bound to a modifier+key handler.

Import:

import type { KeyboardCommand } from '@mnaoumov/obsidian-lib/modals/modal-command-builder';

Signature:

export interface KeyboardCommand extends CommandBase

Extends: CommandBase

Properties

PropertyTypeDescription
checkIsAvailable?() => booleanWhether the control can be used right now. When it returns false the control is rendered **disabled rather than removed**, so the strip does not reflow under the pointer as modes change — which on a phone means a mis-tap.

Re-read by ModalCommands.refresh. When omitted, the builder never touches the control's disabled state, leaving whatever CheckboxCommand.onInit / DropDownCommand.onInit set.
(Inherited from CommandBase)
checkIsOn?() => booleanWhether the command reads as ON. Supply it for a toggle whose state lives outside the strip; omit it for an action, which does something and is done. A CheckboxCommand needs no equivalent — its checkbox element is the state.

Re-read by ModalCommands.refresh.
keystringThe key that activates the command.
(Inherited from CommandBase)
modifiers?Modifier[]The modifiers combined with CommandBase.key. When omitted, no modifiers are required.
(Inherited from CommandBase)
onActivate?($event: MouseEvent) => voidThe pointer route into the same handler the shortcut runs. Required for the command to render a button in ModalCommandsRenderMode.Buttons mode — on a phone there is no modifier key to press, so this is the only way in.
onKey?($event: KeyboardEvent, context: KeymapContext) => booleanThe handler invoked when the shortcut is pressed. When omitted, the command is a hint only and no scope handler is registered.
purposestringThe human-readable description shown next to the control.
(Inherited from CommandBase)