Navigation & Menus
@hacline/ui/trigger-menuTriggerMenu
Open inline suggestions at the text caret when specific characters are typed.
Usage
Type @ to filter collaborators and press Enter to insert a mention. Each entry in triggers configures its trigger character and candidate list.
"use client";
import {
TriggerMenu,
TriggerMenuContent,
TriggerMenuEmpty,
TriggerMenuInput,
TriggerMenuList,
} from "@/components/ui/hacline/components/trigger-menu";
import type { TriggerDefinition } from "@/components/ui/hacline/components/trigger-menu";
const triggers: TriggerDefinition<string>[] = [
{
char: "@",
items: [
{ label: "Lin Yu", value: "lin-yu" },
{ label: "Zhou Ning", value: "zhou-ning" },
{ label: "Chen Jia", value: "chen-jia" },
],
},
];
export const Example = () => (
<div className="w-full max-w-sm">
<TriggerMenu triggers={triggers}>
<TriggerMenuInput
aria-label="Team message"
placeholder="Type @ to mention a teammate"
rows={3}
/>
<TriggerMenuContent sideOffset={6}>
<TriggerMenuEmpty>No matching teammates</TriggerMenuEmpty>
<TriggerMenuList />
</TriggerMenuContent>
</TriggerMenu>
</div>
);Line-Start Slash Commands
Type / at the start of a line to open Markdown suggestions and generate formatted text via insert.
"use client";
import {
TriggerMenu,
TriggerMenuInput,
} from "@/components/ui/hacline/components/trigger-menu";
import type { TriggerDefinition } from "@/components/ui/hacline/components/trigger-menu";
const commands: TriggerDefinition[] = [
{
boundary: "line",
char: "/",
insert: ({ value }) => value,
items: [
{ label: "Task item", value: "- [ ] " },
{ label: "Heading 2", value: "## " },
],
},
];
export const Example = () => (
<TriggerMenu triggers={commands}>
<TriggerMenuInput
aria-label="Slash command editor"
className="max-w-sm"
placeholder="Type / at line start to insert Markdown"
rows={3}
/>
</TriggerMenu>
);Parts
| Part | Description |
|---|---|
TriggerMenuContent | The popup that holds the suggestions, anchored at the caret. |
TriggerMenuEmpty | Shown while no item matches. Rendering it keeps the menu open with no matches; without it, the menu closes until something matches. |
TriggerMenuGroup | A group of items, named by its TriggerMenuGroupLabel. |
TriggerMenuGroupLabel | The group's heading, which names the group. |
TriggerMenuHint | Ghost text at the caret for the arguments still to type, like <name>. Without children, the hints. |
TriggerMenuInput | The text field the menu suggests into: a <textarea>, or an <input> through render. |
TriggerMenuItem | A suggestion. Choosing it inserts it into the text. |
TriggerMenuItemIcon | An icon inside a suggestion. Screen readers, typeahead and filtering skip it, and mirror flips it in right-to-left text. |
TriggerMenuItems | Renders data items. Used by data menus, and available for custom layouts. |
TriggerMenuList | The listbox. Without children, it renders the current trigger's items, filtered. |
TriggerMenuSeparator | A line between items or groups, hidden from screen readers. |
TriggerMenuStatus | A polite status, outside the popup. Without children, it says the count and the keys once typing pauses. |