Dropdown
Floating menu for displaying a list of actions or options. Uses Popover for the popup.
package showcase
import (
"github.com/templui/templui/components/button"
"github.com/templui/templui/components/dropdown"
"github.com/templui/templui/components/icon"
)
templ DropdownDefault() {
@dropdown.Dropdown() {
@dropdown.Trigger() {
@button.Button(button.Props{
Variant: button.VariantOutline,
}) {
Open
}
}
@dropdown.Content(dropdown.ContentProps{
Class: "w-56",
}) {
@dropdown.Label() {
My Account
}
@dropdown.Separator()
@dropdown.Group() {
@dropdown.Item() {
Team
}
@dropdown.Sub() {
@dropdown.SubTrigger() {
<span class="flex items-center">
@icon.Users(icon.Props{Class: "size-4 mr-2"})
Invite users
</span>
}
@dropdown.SubContent() {
@dropdown.Item() {
<span class="flex items-center">
@icon.Mail(icon.Props{Class: "size-4 mr-2"})
Email
</span>
}
@dropdown.Item() {
<span class="flex items-center">
@icon.MessageSquare(icon.Props{Class: "size-4 mr-2"})
Message
</span>
}
@dropdown.Separator()
@dropdown.Item() {
More...
}
}
}
@dropdown.Item() {
New Team
@dropdown.Shortcut() {
⌘+T
}
}
}
@dropdown.Separator()
@dropdown.Item(dropdown.ItemProps{
Href: "https://github.com",
Target: "_blank",
}) {
<span class="flex items-center">
@icon.Github(icon.Props{Class: "size-4 mr-2"})
GitHub
</span>
}
@dropdown.Item() {
<span class="flex items-center">
@icon.LifeBuoy(icon.Props{Class: "size-4 mr-2"})
Support
</span>
}
@dropdown.Item(dropdown.ItemProps{
Disabled: true,
}) {
<span class="flex items-center">
@icon.Code(icon.Props{Class: "size-4 mr-2"})
API
</span>
}
@dropdown.Separator()
@dropdown.Item() {
<span class="flex items-center">
@icon.LogOut(icon.Props{Class: "size-4 mr-2"})
Log out
</span>
@dropdown.Shortcut() {
⇧⌘Q
}
}
}
}
}
Installation
templui add dropdownLoad the script once in your layout:
<head>
@dropdown.Script()
</head>import "github.com/templui/templui/components/dropdown"Load the script once in your layout:
<head>
@dropdown.Script()
</head>API Reference
Dropdown
| Name | Type | Default |
|---|---|---|
Unique identifier for the dropdown (used internally for context) | | |
Trigger
| Name | Type | Default |
|---|---|---|
Unique identifier for the trigger element | | |
Additional CSS classes to apply to the trigger | | |
Additional HTML attributes to apply to the trigger | | |
Content
| Name | Type | Default |
|---|---|---|
Unique identifier for the content element | | |
Additional CSS classes to apply to the content | | |
Additional HTML attributes to apply to the content | | |
Position of the dropdown relative to trigger (e.g., PlacementBottomEnd, PlacementTopStart) | | |
Group
| Name | Type | Default |
|---|---|---|
Unique identifier for the group element | | |
Additional CSS classes to apply to the group | | |
Additional HTML attributes to apply to the group | | |
Label
| Name | Type | Default |
|---|---|---|
Unique identifier for the label element | | |
Additional CSS classes to apply to the label | | |
Additional HTML attributes to apply to the label | | |
Item
| Name | Type | Default |
|---|---|---|
Unique identifier for the item element | | |
Additional CSS classes to apply to the item | | |
Additional HTML attributes to apply to the item | | |
Whether the item is disabled | | |
URL to navigate to when item is clicked (renders as anchor) | | |
Target attribute for anchor items | | |
Whether to prevent dropdown from closing when item is clicked | | |
Separator
| Name | Type | Default |
|---|---|---|
Unique identifier for the separator element | | |
Additional CSS classes to apply to the separator | | |
Additional HTML attributes to apply to the separator | | |
Shortcut
| Name | Type | Default |
|---|---|---|
Unique identifier for the shortcut element | | |
Additional CSS classes to apply to the shortcut | | |
Additional HTML attributes to apply to the shortcut | | |
Sub
| Name | Type | Default |
|---|---|---|
Unique identifier for the submenu container | | |
Additional CSS classes to apply to the submenu container | | |
Additional HTML attributes to apply to the submenu container | | |
SubTrigger
| Name | Type | Default |
|---|---|---|
Unique identifier for the submenu trigger | | |
Additional CSS classes to apply to the submenu trigger | | |
Additional HTML attributes to apply to the submenu trigger | | |
SubContent
| Name | Type | Default |
|---|---|---|
Unique identifier for the submenu content | | |
Additional CSS classes to apply to the submenu content | | |
Additional HTML attributes to apply to the submenu content | | |