aiellie

Search

Find a component, template or page

GitHub
Components

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.

fig. 01 · open it full screen from the corner

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

  1. Wrap the input

    It goes inside Composer, around ComposerInput, and reads the text from the composer.

    components/chat-input.tsx
    import {
      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 /summarize into 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

PropTypeDefaultDescription
commandsSlashCommand[]required
onSelect(command: SlashCommand) => voidCalled with the command picked. Left out, the field becomes /<id> .
emptyMessagestring"No commands match"

All other div props are forwarded.

SlashCommand

FieldTypeDefaultDescription
idstringrequiredWhat's typed after the slash.
descriptionstring
iconIconSvgElementA Hugeicons glyph.