Command
Fast, composable, unstyled command menu.
- Suggestions
- Calendar
- Search emoji
- Launch
- Settings
- Profile⌘P
- Mail⌘B
- Setting⌘S
Installation
npx solidui-cli@latest add command
Usage
import {
Command,
CommandInput,
CommandItem,
CommandItemLabel,
CommandList
} from "@/components/ui/command"
const ALL_OPTIONS = ["Apple", "Banana", "Blueberry", "Grapes", "Pineapple"]
<Command
options={ALL_OPTIONS}
itemComponent={(props) => (
<CommandItem item={props.item}>
<CommandItemLabel>{props.item.rawValue}</CommandItemLabel>
</CommandItem>
)}
>
<CommandInput />
<CommandList />
</Command>
Examples
Dialog
Press ⌘J
To show the command menu in a dialog, use the <CommandDialog />
component.
export function CommandMenu() {
const [open, setOpen] = createSignal(false)
createEffect(() => {
const down = (e: KeyboardEvent) => {
if (e.key === "j" && (e.metaKey || e.ctrlKey)) {
e.preventDefault()
setOpen((open) => !open)
}
}
document.addEventListener("keydown", down)
onCleanup(() => {
document.removeEventListener("keydown", down)
})
})
return (
<CommandDialog
options={ALL_OPTIONS}
itemComponent={(props) => (
<CommandItem item={props.item}>
<CommandItemLabel>{props.item.rawValue}</CommandItemLabel>
</CommandItem>
)}
>
<CommandInput />
<CommandList />
</CommandDialog>
)
}