CommandInput

A plain text input that also handles slash-style commands: typing the trigger character (/ by default) opens a filtered, keyboard-navigable command menu; typing anything else behaves like a normal text field.

Installation

npx dafink-ui add command-input

Demo

Props

NameTypeDefaultDescription
valuestring-Controlled input value.
onChange(value: string) => void-Called on every text change, including internal completions/clears.
commandsCommandOption[]-Array of { name, description?, icon? } objects available for autocomplete.
onCommand(command: CommandOption) => void-Called when a command is executed (Enter or pointer-select on a menu item).
triggerstring'/'Character that opens the command menu when it is the first character typed.
menuSide'top' | 'bottom''top'Which side of the input the menu opens on.
classNamestring''Additional classes on the root wrapper element.

Accessibility

CommandInput is a non-modal combobox, not a dialog: focus never leaves the text input. Opening the menu doesn't move focus anywhere — the active match is tracked virtually via aria-activedescendant on the role="combobox" input, which also carries aria-expanded and aria-controls pointing at the role="listbox" menu. There is no focus trap.

KeyFunction
down arrowMoves to the next matching command, wrapping from the last to the first.
up arrowMoves to the previous matching command, wrapping from the first to the last.
homeJumps to the first matching command.
endJumps to the last matching command.
tabCompletes the active command's full name into the input and keeps the menu open, without running it; when nothing is active, Tab behaves natively and closes the menu.
enterRuns the active command: calls onCommand, clears the input, and closes the menu.
escapeCloses the menu; focus stays in the input.