Skip to content

Select: dropdown selection

Build dropdowns with Select. This page includes a runnable example, all props, and behavior constraints.

Complete example

Complete environment setup first. Copy this complete main.go and run go run ..

go
package main

import (
	"github.com/dxui-org/dxui"
	"log"
)

func main() {
	value := "go"
	app := dxui.NewApp(dxui.AppOptions{
		Title:      "Select",
		Width:      640,
		Height:     480,
		Background: dxui.RGBA(248, 250, 252, 255),
	})
	if err := app.Run(func() dxui.View {
		return dxui.Box(
			dxui.BoxProps{
				Gap: 16,
				Style: dxui.Style{
					Padding: dxui.Padding(24),
				},
			},
			dxui.Select(dxui.SelectProps{
				Value:       value,
				OnChange:    dxui.Assign(&value),
				Placeholder: "Choose",
				Options: []dxui.SelectOption{
					{
						Value: "go",
						Label: "Go",
					},
					{
						Value: "rust",
						Label: "Rust",
					},
					{
						Value:    "later",
						Label:    "Later",
						Disabled: true,
					},
				},
			}),
		)
	}); err != nil {

		log.Fatal(err)
	}
}

Parameters and API

go
func Select(props SelectProps) View
FieldTypePurpose, defaults, and constraints
KeystringStable unique identity within one parent; empty by default. Use business IDs in dynamic lists, not changing indices.
StyleStyleLocal layout, paint, and text styling; zero uses intrinsic sizes and theme defaults.
TokenComponentTokenComponent theme entry; empty selects its default.
StatesStateStylesPaint patches for actual interaction states; cannot fabricate state or change layout.
PointerPointerBehaviorDefaults to PointerAuto; PointerNone excludes the entire subtree from pointer participation, unlike Disabled.
ValuestringCurrent application-owned value; see this page for behavior and zero-value semantics.
Options[]SelectOptionCopied option list; nonempty unique values, at most 4096 items.
PlaceholderstringDisplayed for an empty Value; defaults to empty.
DisabledboolDefaults to false; true removes focus and cancels interaction on interactive components.
OnChangefunc(string)Proposes the complete new value; write it to state for the next build. See behavior for nil callbacks.

Behavior and limitations

Option Value must be nonempty and unique for reorder identity. Empty lists and unmatched Value are supported. Nil OnChange still permits opening, browsing, and closing without accepting a selection. Enter/Space, arrows, Home/End, Escape, and Tab are supported; disabled options are skipped. The overlay escapes ancestor Scroll clipping and flips/clamps at window edges. Not a native system selector or virtualized list; at most 4096 items.

All components share identity, style, and pointer rules. See full declarations for referenced enums, structs, and comments. Running examples explains build verification.