Skip to content

Command

Download .md

Command searches menus and records as you type, and powers the search in the dashboard’s header card.

  • Use it for a global search over menus and records, opened with ⌘K or Ctrl+K.
  • Use an Input to filter one table.
React
Vue
Menu
Rilis
Royalti
Dokumen
Pengaturan⌘,

A page without the dashboard frame can use a floating search card on its own: a card (rounded-lg border border-border bg-card shadow-md) that looks like a search field and opens the command palette in a dialog. Inside the Dashboard frame, the search sits in the header card instead.

React
Vue
import * as React from "react"
import { SearchIcon } from "lucide-react"
import {
Command,
CommandDialog,
CommandEmpty,
CommandGroup,
CommandInput,
CommandItem,
CommandList,
} from "@/components/ui/command"
/** The floating search card of the Alt A dashboard header: a card-styled trigger that opens the command palette. */
export default function SearchCardDemo() {
const [open, setOpen] = React.useState(false)
React.useEffect(() => {
const onKey = (e: KeyboardEvent) => {
if (e.key === "k" && (e.metaKey || e.ctrlKey)) {
// One palette per keypress: the first listener claims it, so other ⌘K handlers stay closed.
if (e.defaultPrevented) return
e.preventDefault()
e.stopPropagation()
setOpen((o) => !o)
}
}
document.addEventListener("keydown", onKey)
return () => document.removeEventListener("keydown", onKey)
}, [])
return (
<>
<button
type="button"
onClick={() => setOpen(true)}
className="flex h-12 w-full max-w-lg items-center gap-3 rounded-lg border border-border bg-card px-4 text-left text-sm text-muted-foreground shadow-md outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50"
>
<SearchIcon className="size-4" />
<span className="flex-1">Cari rilis, artis, atau dokumen</span>
<kbd className="rounded-sm border border-border bg-muted px-1.5 font-mono text-xs">⌘K</kbd>
</button>
<CommandDialog open={open} onOpenChange={setOpen}>
{/* In Base UI, CommandDialog is only the window: the palette inside is a Command. */}
<Command>
<CommandInput placeholder="Cari rilis, artis, atau dokumen" />
<CommandList>
<CommandEmpty>Tidak ada yang cocok.</CommandEmpty>
<CommandGroup heading="Rilis">
<CommandItem>Senja di Kota</CommandItem>
<CommandItem>Kaset Pertama</CommandItem>
</CommandGroup>
<CommandGroup heading="Menu">
<CommandItem>Royalti</CommandItem>
<CommandItem>Dokumen</CommandItem>
</CommandGroup>
</CommandList>
</Command>
</CommandDialog>
</>
)
}
1234
  1. 1Search field
  2. 2Group heading
  3. 3Highlighted result
  4. 4Keyboard shortcut

A search input with a border line under it, then groups of items. Items use radius-md and the highlighted item uses accent. In a dialog the window uses radius-xl; inline, the list sits on radius-lg.

Inline (Command) or in a dialog (CommandDialog).

React Vue Flutter Type Default Use
CommandDialog open onOpenChange CommandDialog v-model:open showShadSheet boolean false Opens the palette. In React, put a Command inside it; in Vue it is built in.
CommandInput placeholder CommandInput placeholder ShadInput placeholder string none What to search for.
CommandItem onSelect CommandItem @select onPressed function none Runs when an item is chosen.
CommandEmpty CommandEmpty empty-state text element none Shown when nothing matches.
import { BarChart3Icon, DiscIcon, FileTextIcon, SettingsIcon } from "lucide-react"
import {
Command,
CommandEmpty,
CommandGroup,
CommandInput,
CommandItem,
CommandList,
CommandShortcut,
} from "@/components/ui/command"
export default function CommandDemo() {
return (
<Command className="w-full max-w-sm border border-border shadow-md">
<CommandInput placeholder="Cari menu atau rilis" />
<CommandList>
<CommandEmpty>Tidak ada yang cocok.</CommandEmpty>
<CommandGroup heading="Menu">
<CommandItem>
<DiscIcon />
Rilis
</CommandItem>
<CommandItem>
<BarChart3Icon />
Royalti
</CommandItem>
<CommandItem>
<FileTextIcon />
Dokumen
</CommandItem>
<CommandItem>
<SettingsIcon />
Pengaturan
<CommandShortcut>⌘,</CommandShortcut>
</CommandItem>
</CommandGroup>
</CommandList>
</Command>
)
}
Terminal window
npx shadcn@latest add https://design.sosialoka.tech/r/react/command.json
  • Arrow keys move through items, Enter chooses, Escape closes the dialog.
  • Show the shortcut (⌘K) on the search card so people find it.