Skip to main content

Dropdown

A selection menu that displays a list of items.

Basic Usage​

// Themed (recommended)
theme.DropdownOf(ctx, selectedPlan, []widgets.DropdownItem[string]{
{Value: "starter", Label: "Starter"},
{Value: "pro", Label: "Pro"},
{Value: "enterprise", Label: "Enterprise"},
}, func(value string) {
s.SetState(func() {
selectedPlan = value
})
}).WithBorderRadius(8)

// Explicit
widgets.Dropdown[string]{
Value: selectedPlan,
Hint: "Select a plan",
Items: []widgets.DropdownItem[string]{
{Value: "starter", Label: "Starter"},
{Value: "pro", Label: "Pro"},
{Value: "enterprise", Label: "Enterprise"},
},
OnChanged: func(value string) {
s.SetState(func() {
selectedPlan = value
})
},
BackgroundColor: colors.Surface,
BorderColor: colors.Outline,
BorderRadius: 8,
SelectedItemColor: colors.SurfaceVariant,
}

Properties​

PropertyTypeDescription
ValueTCurrently selected value
HintstringPlaceholder text when no value is selected
Items[]DropdownItem[T]Available options
OnChangedfunc(T)Called when selection changes
BackgroundColorgraphics.ColorBackground color
BorderColorgraphics.ColorBorder color
BorderRadiusfloat64Corner radius
TextStylegraphics.TextStyleText styling
SelectedItemColorgraphics.ColorHighlight color for the selected row

Explicit Styling Requirements​

Explicit dropdowns require BackgroundColor, BorderColor, TextStyle.Color, and SelectedItemColor if you want a visible selected-row highlight. If you want defaults from the theme, prefer theme.DropdownOf(ctx, ...).