shadcn-templ 2.0 beta. Switch to templUI v1
1.7k

Command

Command menu for search and quick actions.

package examples import (

About

The Command component is a native templ and vanilla JavaScript port of the cmdk component, no external dependencies.

Installation

shadcn-templ add command

Usage

import "github.com/axadrn/shadcn-templ/v2/components/command"
@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() {				Calendar			}			@command.Item() {				Search Emoji			}			@command.Item() {				Calculator			}		}		@command.Separator()		@command.Group(command.GroupProps{Heading: "Settings"}) {			@command.Item() {				Profile			}			@command.Item() {				Billing			}			@command.Item() {				Settings			}		}	}}

Composition

Use the following composition to build a Command:

command.Command├── command.Input└── command.List    ├── command.Empty    ├── command.Group    │   ├── command.Item    │   └── command.Item    ├── command.Separator    └── command.Group        ├── command.Item        └── command.Item

Basic

A simple command menu in a dialog.

Command Palette
Search for a command to run...
package examples import (

Shortcuts

Command Palette
Search for a command to run...
package examples import (

Groups

A command menu with groups, icons and separators.

Command Palette
Search for a command to run...
package examples import (

Scrollable

Scrollable command menu with multiple items.

Command Palette
Search for a command to run...
package examples import (

API Reference

Command

The Command component is the root that manages filtering and selection.

Prop Type Default
ID string -
Label string -
Class string -

Dialog

The command.Dialog component renders the command menu in a dialog. Open it from any element via dialog.TriggerFor(id).

Prop Type Default
ID string -
Title string "Command Palette"
Description string "Search for a command to run..."
ShowCloseButton bool false
Class string -

Input

The command.Input component is the search input that filters the list.

Prop Type Default
Placeholder string -
Disabled bool false
Class string -

List

The command.List component holds the filterable items.

Prop Type Default
Label string "Suggestions"
Class string -

Empty

The command.Empty component shows while no item matches the search.

Prop Type Default
Class string -

Group

The command.Group component wraps related items.

Prop Type Default
Heading string -
Class string -

Item

The command.Item component is a selectable command.

Prop Type Default
Value string -
Disabled bool false
Class string -

Shortcut

The command.Shortcut component displays a keyboard shortcut on an item.

Prop Type Default
Class string -

Separator

The command.Separator component divides groups. It hides while searching unless AlwaysRender is set, exactly like cmdk.

Prop Type Default
AlwaysRender bool false
Class string -