Slash Menu
The commands a slash opens at the start of the composer, filtered as you type and picked with the arrow keys and Enter.
Installation
npx shadcn@latest add "@aiellie/slash-menu"shadcn needs the @aiellie registry in components.json first. npx aiellie add slash-menu adds it on its first run, then installs the same way.
Slash Menu lists the commands a composer can run when a message starts with a slash. It filters as the name is typed, moves with the arrow keys, and picks with Enter or Tab, so Enter runs a command instead of sending. Escape closes it until the text changes.
Getting started
Wrap the input
It goes inside
Composer, aroundComposerInput, and reads the text from the composer.components/chat-input.tsximport { Composer, ComposerFooter, ComposerInput, ComposerSubmit, } from "@/components/aiellie/composer" import { SlashMenu, type SlashCommand } from "@/components/aiellie/slash-menu" const COMMANDS: SlashCommand[] = [ { id: "summarize", description: "Sum up the thread so far" }, { id: "explain", description: "Explain the last reply simply" }, ] export function ChatInput({ onSend }: { onSend: (text: string) => void }) { return ( <Composer onSubmit={onSend}> <SlashMenu commands={COMMANDS}> <ComposerInput /> </SlashMenu> <ComposerFooter> <ComposerSubmit /> </ComposerFooter> </Composer> ) }Picking a command writes
/summarizeinto the field, ready for the rest of the message.
Anatomy
<div data-slot="slash-menu">
<textarea data-slot="composer-input" aria-autocomplete="list" aria-expanded aria-activedescendant />
<div role="listbox"> {/* above the field, while open */}
<div role="option" aria-selected data-highlighted />
</div>
</div>Focus stays in the field the whole time. The list is announced through aria-activedescendant, and the keys it answers are caught before the field sees them.
The list floats above the field as glass with a shadow, and scrolls past six or so commands.
Examples
Run a command at once
onSelect takes over from writing the command into the field, for commands that act straight away.
Pick a command to run it straight away.
API reference
SlashMenu
| Prop | Type | Default | Description |
|---|---|---|---|
commands | SlashCommand[] | required | |
onSelect | (command: SlashCommand) => void | Called with the command picked. Left out, the field becomes /<id> . | |
emptyMessage | string | "No commands match" |
All other div props are forwarded.
SlashCommand
| Field | Type | Default | Description |
|---|---|---|---|
id | string | required | What's typed after the slash. |
description | string | ||
icon | IconSvgElement | A Hugeicons glyph. |