dropdown

package
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 17, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package dropdown provides dropdown menu components with keyboard navigation.

Dropdowns display a list of options or actions when clicked. They support positioning, alignment, keyboard navigation, and click-outside-to-close.

Basic usage:

dropdown.Dropdown(
    dropdown.DropdownProps{
        Position: forgeui.PositionBottom,
        Align:    forgeui.AlignStart,
    },
    button.Button(g.Text("Options")),
    html.Div(g.Text("Dropdown content")),
)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextMenu

func ContextMenu(trigger g.Node, content ...g.Node) g.Node

ContextMenu creates a context menu triggered by right-click.

Context menus appear at the cursor position when right-clicking on the trigger element. They share the same item components as DropdownMenu (items, separators, checkboxes, etc.).

Example:

contextMenu.ContextMenu(
    html.Div(
        html.Class("p-4 border border-border"),
        g.Text("Right-click me"),
    ),
    contextMenu.ContextMenuContent(
        contextMenu.ContextMenuItem(g.Text("Copy")),
        contextMenu.ContextMenuItem(g.Text("Paste")),
        contextMenu.ContextMenuSeparator(),
        contextMenu.ContextMenuItem(g.Text("Delete")),
    ),
)

func ContextMenuCheckboxItem

func ContextMenuCheckboxItem(id, label string, checked bool) g.Node

ContextMenuCheckboxItem creates a checkable context menu item.

func ContextMenuContent

func ContextMenuContent(children ...g.Node) g.Node

ContextMenuContent creates the context menu content panel.

func ContextMenuItem

func ContextMenuItem(children ...g.Node) g.Node

ContextMenuItem creates a context menu item. Same as DropdownMenuItem but closes the context menu on click.

func ContextMenuItemWithIcon

func ContextMenuItemWithIcon(icon, label g.Node) g.Node

ContextMenuItemWithIcon creates a context menu item with an icon.

func ContextMenuLabel

func ContextMenuLabel(text string) g.Node

ContextMenuLabel creates a label for grouping items.

func ContextMenuRadioGroup

func ContextMenuRadioGroup(value string, children ...g.Node) g.Node

ContextMenuRadioGroup creates a radio group container.

func ContextMenuRadioItem

func ContextMenuRadioItem(value, label string) g.Node

ContextMenuRadioItem creates a radio context menu item.

func ContextMenuSeparator

func ContextMenuSeparator() g.Node

ContextMenuSeparator creates a visual separator.

func ContextMenuShortcut

func ContextMenuShortcut(text string) g.Node

ContextMenuShortcut displays a keyboard shortcut hint.

func ContextMenuSub

func ContextMenuSub(trigger g.Node, content ...g.Node) g.Node

ContextMenuSub creates a submenu.

func Dropdown(props DropdownProps, trigger g.Node, content ...g.Node) g.Node

Dropdown creates a basic dropdown with positioning.

The dropdown toggles open/closed on click and closes when clicking outside. It supports positioning and alignment relative to the trigger.

Example:

dropdown.Dropdown(
    dropdown.DropdownProps{
        Position: forgeui.PositionBottom,
        Align:    forgeui.AlignEnd,
    },
    button.Button(g.Text("Menu")),
    html.Div(
        html.A(html.Href("#"), g.Text("Option 1")),
        html.A(html.Href("#"), g.Text("Option 2")),
    ),
)
func DropdownClose(child g.Node) g.Node

DropdownClose wraps an element to close the dropdown when clicked.

func DropdownMenu(children ...g.Node) g.Node

DropdownMenu creates a dropdown menu container with compound API.

DropdownMenu provides a full-featured menu system with:

  • Menu items with icons
  • Keyboard navigation (arrows, enter, escape)
  • Separators and labels
  • Checkable items
  • Radio items
  • Submenu support
  • Keyboard shortcuts display

Example:

dropdown.DropdownMenu(
    dropdown.DropdownMenuTrigger(button.Button(g.Text("Options"))),
    dropdown.DropdownMenuContent(
        dropdown.DropdownMenuItem(g.Text("Profile")),
        dropdown.DropdownMenuItem(g.Text("Settings")),
        dropdown.DropdownMenuSeparator(),
        dropdown.DropdownMenuItem(g.Text("Logout")),
    ),
)
func DropdownMenuCheckboxItem(id, label string, checked bool) g.Node

DropdownMenuCheckboxItem creates a checkable menu item.

func DropdownMenuContent(children ...g.Node) g.Node

DropdownMenuContent creates the menu content panel.

func DropdownMenuContentWithAlign(align forgeui.Align, children ...g.Node) g.Node

DropdownMenuContentWithAlign creates menu content with custom alignment

func DropdownMenuItem(children ...g.Node) g.Node

DropdownMenuItem creates a menu item.

func DropdownMenuItemWithIcon(icon, label g.Node) g.Node

DropdownMenuItemWithIcon creates a menu item with an icon.

func DropdownMenuLabel(text string) g.Node

DropdownMenuLabel creates a label for grouping items.

func DropdownMenuRadioGroup(value string, children ...g.Node) g.Node

DropdownMenuRadioGroup creates a radio group container.

func DropdownMenuRadioItem(value, label string) g.Node

DropdownMenuRadioItem creates a radio menu item.

func DropdownMenuSeparator() g.Node

DropdownMenuSeparator creates a visual separator.

func DropdownMenuShortcut(text string) g.Node

DropdownMenuShortcut displays a keyboard shortcut hint.

func DropdownMenuSub(trigger g.Node, content ...g.Node) g.Node

DropdownMenuSub creates a submenu.

func DropdownMenuTrigger(child g.Node) g.Node

DropdownMenuTrigger wraps the trigger element.

Types

type DropdownProps struct {
	// Position specifies where the dropdown appears relative to trigger
	Position forgeui.Position

	// Align specifies how the dropdown aligns with the trigger
	Align forgeui.Align

	// Class adds additional CSS classes
	Class string
}

DropdownProps defines configuration for a dropdown

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL