package examples import (package examples import ( "github.com/axadrn/shadcn-templ/v2/components/command" "github.com/axadrn/shadcn-templ/v2/components/icon") templ CommandDemo() { @command.Command(command.Props{Class: "max-w-sm rounded-lg border"}) { @command.Input(command.InputProps{Placeholder: "Type a command or search..."}) @command.List() { @command.Empty() { No results found. } @command.Group(command.GroupProps{Heading: "Suggestions"}) { @command.Item() { @icon.Calendar() <span>Calendar</span> } @command.Item() { @icon.Smile() <span>Search Emoji</span> } @command.Item(command.ItemProps{Disabled: true}) { @icon.Calculator() <span>Calculator</span> } } @command.Separator() @command.Group(command.GroupProps{Heading: "Settings"}) { @command.Item() { @icon.User() <span>Profile</span> @command.Shortcut() { ⌘P } } @command.Item() { @icon.CreditCard() <span>Billing</span> @command.Shortcut() { ⌘B } } @command.Item() { @icon.Settings() <span>Settings</span> @command.Shortcut() { ⌘S } } } } }}About
The Command component is a native templ and vanilla JavaScript port of the cmdk component, no external dependencies.
Installation
Usage
Composition
Use the following composition to build a Command:
Basic
A simple command menu in a dialog.
package examples import (package examples import ( "github.com/axadrn/shadcn-templ/v2/components/button" "github.com/axadrn/shadcn-templ/v2/components/command" "github.com/axadrn/shadcn-templ/v2/components/dialog") templ CommandBasic() { <div class="flex flex-col gap-4"> @button.Button(button.Props{ Variant: button.VariantOutline, Class: "w-fit", Attributes: dialog.TriggerFor("command-basic"), }) { Open Menu } @command.Dialog(command.DialogProps{ID: "command-basic"}) { @command.Command() { @command.Input(command.InputProps{Placeholder: "Type a command or search..."}) @command.List() { @command.Empty() { No results found. } @command.Group(command.GroupProps{Heading: "Suggestions"}) { @command.Item() { Calendar } @command.Item() { Search Emoji } @command.Item() { Calculator } } } } } </div>}Shortcuts
package examples import (package examples import ( "github.com/axadrn/shadcn-templ/v2/components/button" "github.com/axadrn/shadcn-templ/v2/components/command" "github.com/axadrn/shadcn-templ/v2/components/dialog" "github.com/axadrn/shadcn-templ/v2/components/icon") templ CommandShortcuts() { <div class="flex flex-col gap-4"> @button.Button(button.Props{ Variant: button.VariantOutline, Class: "w-fit", Attributes: dialog.TriggerFor("command-shortcuts"), }) { Open Menu } @command.Dialog(command.DialogProps{ID: "command-shortcuts"}) { @command.Command() { @command.Input(command.InputProps{Placeholder: "Type a command or search..."}) @command.List() { @command.Empty() { No results found. } @command.Group(command.GroupProps{Heading: "Settings"}) { @command.Item() { @icon.User() <span>Profile</span> @command.Shortcut() { ⌘P } } @command.Item() { @icon.CreditCard() <span>Billing</span> @command.Shortcut() { ⌘B } } @command.Item() { @icon.Settings() <span>Settings</span> @command.Shortcut() { ⌘S } } } } } } </div>}Groups
A command menu with groups, icons and separators.
package examples import (package examples import ( "github.com/axadrn/shadcn-templ/v2/components/button" "github.com/axadrn/shadcn-templ/v2/components/command" "github.com/axadrn/shadcn-templ/v2/components/dialog" "github.com/axadrn/shadcn-templ/v2/components/icon") templ CommandGroups() { <div class="flex flex-col gap-4"> @button.Button(button.Props{ Variant: button.VariantOutline, Class: "w-fit", Attributes: dialog.TriggerFor("command-groups"), }) { Open Menu } @command.Dialog(command.DialogProps{ID: "command-groups"}) { @command.Command() { @command.Input(command.InputProps{Placeholder: "Type a command or search..."}) @command.List() { @command.Empty() { No results found. } @command.Group(command.GroupProps{Heading: "Suggestions"}) { @command.Item() { @icon.Calendar() <span>Calendar</span> } @command.Item() { @icon.Smile() <span>Search Emoji</span> } @command.Item() { @icon.Calculator() <span>Calculator</span> } } @command.Separator() @command.Group(command.GroupProps{Heading: "Settings"}) { @command.Item() { @icon.User() <span>Profile</span> @command.Shortcut() { ⌘P } } @command.Item() { @icon.CreditCard() <span>Billing</span> @command.Shortcut() { ⌘B } } @command.Item() { @icon.Settings() <span>Settings</span> @command.Shortcut() { ⌘S } } } } } } </div>}Scrollable
Scrollable command menu with multiple items.
package examples import (package examples import ( "github.com/axadrn/shadcn-templ/v2/components/button" "github.com/axadrn/shadcn-templ/v2/components/command" "github.com/axadrn/shadcn-templ/v2/components/dialog" "github.com/axadrn/shadcn-templ/v2/components/icon") templ CommandScrollable() { <div class="flex flex-col gap-4"> @button.Button(button.Props{ Variant: button.VariantOutline, Class: "w-fit", Attributes: dialog.TriggerFor("command-scrollable"), }) { Open Menu } @command.Dialog(command.DialogProps{ID: "command-scrollable"}) { @command.Command() { @command.Input(command.InputProps{Placeholder: "Type a command or search..."}) @command.List() { @command.Empty() { No results found. } @command.Group(command.GroupProps{Heading: "Navigation"}) { @command.Item() { @icon.House() <span>Home</span> @command.Shortcut() { ⌘H } } @command.Item() { @icon.Inbox() <span>Inbox</span> @command.Shortcut() { ⌘I } } @command.Item() { @icon.FileText() <span>Documents</span> @command.Shortcut() { ⌘D } } @command.Item() { @icon.Folder() <span>Folders</span> @command.Shortcut() { ⌘F } } } @command.Separator() @command.Group(command.GroupProps{Heading: "Actions"}) { @command.Item() { @icon.Plus() <span>New File</span> @command.Shortcut() { ⌘N } } @command.Item() { @icon.FolderPlus() <span>New Folder</span> @command.Shortcut() { ⇧⌘N } } @command.Item() { @icon.Copy() <span>Copy</span> @command.Shortcut() { ⌘C } } @command.Item() { @icon.Scissors() <span>Cut</span> @command.Shortcut() { ⌘X } } @command.Item() { @icon.ClipboardPaste() <span>Paste</span> @command.Shortcut() { ⌘V } } @command.Item() { @icon.Trash() <span>Delete</span> @command.Shortcut() { ⌫ } } } @command.Separator() @command.Group(command.GroupProps{Heading: "View"}) { @command.Item() { @icon.LayoutGrid() <span>Grid View</span> } @command.Item() { @icon.List() <span>List View</span> } @command.Item() { @icon.ZoomIn() <span>Zoom In</span> @command.Shortcut() { ⌘+ } } @command.Item() { @icon.ZoomOut() <span>Zoom Out</span> @command.Shortcut() { ⌘- } } } @command.Separator() @command.Group(command.GroupProps{Heading: "Account"}) { @command.Item() { @icon.User() <span>Profile</span> @command.Shortcut() { ⌘P } } @command.Item() { @icon.CreditCard() <span>Billing</span> @command.Shortcut() { ⌘B } } @command.Item() { @icon.Settings() <span>Settings</span> @command.Shortcut() { ⌘S } } @command.Item() { @icon.Bell() <span>Notifications</span> } @command.Item() { @icon.CircleQuestionMark() <span>Help & Support</span> } } @command.Separator() @command.Group(command.GroupProps{Heading: "Tools"}) { @command.Item() { @icon.Calculator() <span>Calculator</span> } @command.Item() { @icon.Calendar() <span>Calendar</span> } @command.Item() { @icon.Image() <span>Image Editor</span> } @command.Item() { @icon.Code() <span>Code Editor</span> } } } } } </div>}API Reference
Command
The Command component is the root that manages filtering and selection.
Dialog
The command.Dialog component renders the command menu in a dialog. Open it
from any element via dialog.TriggerFor(id).
Input
The command.Input component is the search input that filters the list.
List
The command.List component holds the filterable items.
Empty
The command.Empty component shows while no item matches the search.
Group
The command.Group component wraps related items.
Item
The command.Item component is a selectable command.
Shortcut
The command.Shortcut component displays a keyboard shortcut on an item.
Separator
The command.Separator component divides groups. It hides while searching
unless AlwaysRender is set, exactly like cmdk.