Navigation & Menus
@hacline/ui/commandCommand
Filter and execute a set of named commands.
Usage
Type a command keyword, then press Enter or click a result. Selected actions are passed to your application via onAction, and commands can be organized into groups.
"use client";
import { useState } from "react";
import {
Command,
CommandEmpty,
CommandGroup,
CommandGroupLabel,
CommandInput,
CommandItem,
CommandList,
} from "@/components/ui/hacline/components/command";
export const Example = () => {
const [action, setAction] = useState("Waiting for a command");
return (
<div className="grid w-full max-w-xs gap-2">
<Command onAction={setAction}>
<CommandInput
aria-label="Search workspace commands"
placeholder="Search commands"
/>
<CommandEmpty>No matching commands</CommandEmpty>
<CommandList>
<CommandGroup>
<CommandGroupLabel>Workspace</CommandGroupLabel>
<CommandItem value="New draft">New draft</CommandItem>
<CommandItem value="Copy link">Copy link</CommandItem>
<CommandItem value="Open activity log">
Open activity log
</CommandItem>
</CommandGroup>
</CommandList>
</Command>
<output className="text-hl-fg-muted text-xs">{action}</output>
</div>
);
};Switching Between Command Pages
Open the export format page first, then select Markdown or HTML. Press Backspace while the search input is empty to return to the previous page.
"use client";
import { useState } from "react";
import {
Command,
CommandInput,
CommandItem,
CommandList,
CommandPage,
} from "@/components/ui/hacline/components/command";
export const Example = () => {
const [format, setFormat] = useState("Markdown");
return (
<div className="grid w-full max-w-xs gap-2">
<Command onAction={setFormat}>
<CommandInput
aria-label="Search export commands"
placeholder="Search export commands"
/>
<CommandList>
<CommandPage>
<CommandItem page="format" value="choose-format">
Choose export format
</CommandItem>
</CommandPage>
<CommandPage value="format">
<CommandItem value="Markdown">Markdown</CommandItem>
<CommandItem value="HTML">HTML</CommandItem>
</CommandPage>
</CommandList>
</Command>
<output className="text-hl-fg-muted text-xs">
Export format: {format}
</output>
</div>
);
};Parts
| Part | Description | Extended Props |
|---|---|---|
CommandEmpty | Shown while no command matches. Its message is announced when it appears. Place it outside the list. | — |
CommandGroup | A group of commands. It hides while none of its commands matches the search. | — |
CommandGroupLabel | A group's heading, which names it. | — |
CommandInput | The search field. It keeps focus while arrow keys move the highlight. Name it with aria-label. | size |
CommandItem | A command. Pressing it, or Enter while it's highlighted, runs it, with its value passed to the command's onAction. | — |
CommandItemIcon | An icon inside a command. Screen readers, typeahead and filtering skip it, and mirror flips it in right-to-left text. | — |
CommandItems | Renders data commands. Used by data command lists, and available for custom layouts. | — |
CommandItemText | The command's text, with the part the search matched in <mark>. Without string content, it shows the command's label. | — |
CommandList | The listbox. Without children, it renders the command's items, ranked as the user types. | — |
CommandPage | Commands shown while this page is on top. Without value, it's the first page. Renders no element. | — |
CommandSeparator | A line between groups. Composed separators hide while the list is filtered. | — |
CommandShortcut | The keys of a command's shortcut, formatted for the platform. Inside a command, its shortcut. | — |
CommandStatus | A polite live region for loading and result counts. Its content is yours, usually a function of its state. | — |
Props
Prop
Type