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

Dropdown Menu

Displays a menu to the user, such as a set of actions or functions, triggered by a button.

package examples import (

Installation

shadcn-templ add dropdown-menu

Usage

import "github.com/axadrn/shadcn-templ/v2/components/dropdownmenu"
@dropdownmenu.DropdownMenu() {	@button.Button(button.Props{		Variant:    button.VariantOutline,		Attributes: dropdownmenu.Trigger(ctx),	}) {		Open	}	@dropdownmenu.Content() {		@dropdownmenu.Group() {			@dropdownmenu.Label() {				My Account			}			@dropdownmenu.Item() {				Profile			}			@dropdownmenu.Item() {				Billing			}		}		@dropdownmenu.Separator()		@dropdownmenu.Group() {			@dropdownmenu.Item() {				Team			}			@dropdownmenu.Item() {				Subscription			}		}	}}

Composition

Use the following composition to build a DropdownMenu:

dropdownmenu.DropdownMenu├── dropdownmenu.Trigger└── dropdownmenu.Content    ├── dropdownmenu.Group    │   ├── dropdownmenu.Label    │   ├── dropdownmenu.Item    │   └── dropdownmenu.Item    ├── dropdownmenu.Separator    ├── dropdownmenu.Group    │   ├── dropdownmenu.Label    │   ├── dropdownmenu.CheckboxItem    │   └── dropdownmenu.CheckboxItem    ├── dropdownmenu.Separator    ├── dropdownmenu.Group    │   ├── dropdownmenu.Label    │   └── dropdownmenu.RadioGroup    │       ├── dropdownmenu.RadioItem    │       └── dropdownmenu.RadioItem    └── dropdownmenu.Sub        ├── dropdownmenu.SubTrigger        └── dropdownmenu.SubContent            └── dropdownmenu.Group                ├── dropdownmenu.Label                ├── dropdownmenu.Item                └── dropdownmenu.Item

Basic

A basic dropdown menu with labels and separators.

package examples import (

Use dropdownmenu.Sub to nest secondary actions.

package examples import (

Shortcuts

Add dropdownmenu.Shortcut to show keyboard hints.

package examples import (

Icons

Combine icons with labels for quick scanning.

package examples import (

Checkboxes

Use dropdownmenu.CheckboxItem for toggles.

package examples import (

Checkboxes Icons

Add icons to checkbox items.

package examples import (

Radio Group

Use dropdownmenu.RadioGroup for exclusive choices.

package examples import (

Radio Icons

Show radio options with icons.

package examples import (

Destructive

Use Variant: dropdownmenu.ItemVariantDestructive for irreversible actions.

package examples import (

Avatar

An account switcher dropdown triggered by an avatar.

package examples import (

Complex

A richer example combining groups, icons, and submenus.

package examples import (

API Reference

Content

The dropdownmenu.Content component is the menu surface, anchored to the trigger.

Prop Type Default
Side SideTop | SideRight | SideBottom | SideLeft SideBottom
Align AlignStart | AlignCenter | AlignEnd AlignStart
SideOffset int 4
AlignOffset int 0
Class string -

Item

The dropdownmenu.Item component is a selectable entry. It renders as a link when Href is set and closes the menu on click.

Prop Type Default
Variant ItemVariantDefault | ItemVariantDestructive ItemVariantDefault
Inset bool false
Disabled bool false
Href string -
Target string -
DisableCloseOnClick bool false
Class string -

CheckboxItem

The dropdownmenu.CheckboxItem component is a toggleable item with a check indicator. It keeps the menu open on click.

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

RadioGroup

The dropdownmenu.RadioGroup component wraps radio items and enforces single selection among them.

Prop Type Default
Class string -

RadioItem

The dropdownmenu.RadioItem component is a single-select item with a dot indicator. It keeps the menu open on click.

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

SubTrigger

The dropdownmenu.SubTrigger component opens a nested submenu on hover. Wrap it with dropdownmenu.SubContent in a dropdownmenu.Sub.

Prop Type Default
Inset bool false
Class string -