Command
Command searches menus and records as you type, and powers the search in the dashboard’s header card.
When to use
Section titled “When to use”- Use it for a global search over menus and records, opened with ⌘K or Ctrl+K.
- Use an Input to filter one table.
Menu
Rilis
Royalti
Dokumen
Pengaturan⌘,
Search card
Section titled “Search card”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.
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> </> )}<script setup lang="ts">import { Search } from "@lucide/vue"import { onBeforeUnmount, onMounted, ref } from "vue"import { 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. */const open = ref(false)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() open.value = !open.value }}onMounted(() => document.addEventListener("keydown", onKey))onBeforeUnmount(() => document.removeEventListener("keydown", onKey))</script>
<template> <button type="button" class="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" @click="open = true" > <Search class="size-4" /> <span class="flex-1">Cari rilis, artis, atau dokumen</span> <kbd class="rounded-sm border border-border bg-muted px-1.5 font-mono text-xs">⌘K</kbd> </button> <CommandDialog v-model:open="open"> <CommandInput placeholder="Cari rilis, artis, atau dokumen" /> <CommandList> <CommandEmpty>Tidak ada yang cocok.</CommandEmpty> <CommandGroup heading="Rilis"> <CommandItem value="senja">Senja di Kota</CommandItem> <CommandItem value="kaset">Kaset Pertama</CommandItem> </CommandGroup> <CommandGroup heading="Menu"> <CommandItem value="royalti">Royalti</CommandItem> <CommandItem value="dokumen">Dokumen</CommandItem> </CommandGroup> </CommandList> </CommandDialog></template>// The floating search card of the dashboard header. It opens a search sheet built like CommandDemo.import 'package:flutter/widgets.dart';import 'package:shadcn_ui/shadcn_ui.dart';
class SearchCardDemo extends StatelessWidget { const SearchCardDemo({super.key});
@override Widget build(BuildContext context) { return ShadCard( width: 512, padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4), child: ShadInput( placeholder: const Text('Cari rilis, artis, atau dokumen'), leading: const Icon(LucideIcons.search, size: 16), readOnly: true, onPressed: () => showShadSheet( context: context, side: ShadSheetSide.top, builder: (context) => const ShadSheet(title: Text('Cari'), child: SizedBox(height: 240)), ), ), ); }}Anatomy
Section titled “Anatomy”- 1Search field
- 2Group heading
- 3Highlighted result
- 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.
Variants
Section titled “Variants”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> )}<script setup lang="ts">import { BarChart3, Disc, FileText, Settings } from "@lucide/vue"import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandShortcut,} from "@/components/ui/command"</script>
<template> <Command class="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 value="rilis"><Disc />Rilis</CommandItem> <CommandItem value="royalti"><BarChart3 />Royalti</CommandItem> <CommandItem value="dokumen"><FileText />Dokumen</CommandItem> <CommandItem value="pengaturan"><Settings />Pengaturan<CommandShortcut>⌘,</CommandShortcut></CommandItem> </CommandGroup> </CommandList> </Command></template>// shadcn_ui has no command palette: filter a list under a ShadInput.import 'package:flutter/widgets.dart';import 'package:shadcn_ui/shadcn_ui.dart';
const menu = ['Rilis', 'Royalti', 'Dokumen', 'Pengaturan'];
class CommandDemo extends StatefulWidget { const CommandDemo({super.key});
@override State<CommandDemo> createState() => _CommandDemoState();}
class _CommandDemoState extends State<CommandDemo> { String query = '';
@override Widget build(BuildContext context) { final matches = menu.where((m) => m.toLowerCase().contains(query.toLowerCase())); return ShadCard( width: 384, padding: const EdgeInsets.all(4), child: Column( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.stretch, children: [ ShadInput( placeholder: const Text('Cari menu atau rilis'), leading: const Icon(LucideIcons.search, size: 16), onChanged: (v) => setState(() => query = v), ), for (final m in matches) ShadButton.ghost(mainAxisAlignment: MainAxisAlignment.start, onPressed: () {}, child: Text(m)), if (matches.isEmpty) const Padding(padding: EdgeInsets.all(12), child: Text('Tidak ada yang cocok.')), ], ), ); }}Install
Section titled “Install”npx shadcn@latest add https://design.sosialoka.tech/r/react/command.jsonnpx shadcn-vue@latest add https://design.sosialoka.tech/r/vue/command.jsonAccessibility
Section titled “Accessibility”- Arrow keys move through items, Enter chooses, Escape closes the dialog.
- Show the shortcut (⌘K) on the search card so people find it.
