01
Overview
Inline caret-anchored slash-command list for textareas and single-line text inputs.
Usage
Guidance
Use When
- Showing a contextual command list at the caret while a user types in a textarea or input.
- Building slash-command insertion flows where the host owns text replacement.
Avoid When
- Exposing a global app launcher — use command-palette instead.
- Selecting from a static form option list — use combobox instead.
02
When to use
Use when
- Showing a contextual command list at the caret while a user types in a textarea or input.
- Building slash-command insertion flows where the host owns text replacement.
Avoid when
- Exposing a global app launcher — use command-palette instead.
- Selecting from a static form option list — use combobox instead.
03
Examples
Slash commands in a textarea
A caret-anchored command menu controlled by a textarea host.
04
Props
| Name | Type | Default | Description |
|---|---|---|---|
listboxId | text | Stable listbox id. Defaults to a generated component id. | |
open bindable | boolean | false | Open state. Bindable. Default false. |
anchor required | HTMLInputElement | HTMLTextAreaElement | null | Text field used as the caret-position anchor. | |
caretIndex | number | Caret offset within the anchor value. Optional — when omitted, it's
derived from the anchor's live selectionEnd. Consumers that already
track trigger-relative caret state (e.g. from detectTrigger) may keep
passing it explicitly; the derivation exists for hosts that don't need
anything more precise than "where the caret currently is." | |
query bindable | text | '' | Query text after the trigger character. Bindable. Default ''. |
items required | snippet | Render command items for the current query. | |
empty | snippet | Optional empty state rendered after item registration settles. | |
placement | 'top''bottom''left''right''top-start''top-end''bottom-start''bottom-end' | 'bottom-start' | Caret-relative placement. Default 'bottom-start'. |
offset | number | 6 | Distance in px between the caret and menu. Default 6. |
label | text | 'Commands' | Accessible listbox label. Default 'Commands'. |
onSelect | (detail: CommandMenuSelection) => void | Invoked when an enabled command is activated. | |
onComplete | (detail: CommandMenuCompletion) => void | Invoked when the user accepts inline ghost-text completion. Passing this
prop is what enables the feature — omit it and no ghost text ever
renders. See command-menu.a11y.md for the full keyboard model. | |
onDismiss | () => void | Invoked when Escape or outside pointerdown dismisses the menu. | |
onStateChange | (state: CommandMenuState) => void | One-way state output for host-owned field ARIA. |