dropdown

package
v1.0.31-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 15 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package dropdown provides a stateful dropdown.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Select

type Select struct {
	// Contextual gives it a context menu (Context).
	elements.Contextual
	// contains filtered or unexported fields
}

Select is a stateful dropdown. Create it once with New and lay it out every frame.

func New

func New(st styles.Styles, options ...string) *Select

New returns a Select with the given styles and options: Background is the dropdown background, Color the text, BorderColor the field border, BorderRadius the corners.

func (*Select) Choose

func (s *Select) Choose(i int)

Choose selects option i and invokes OnChange, as picking it from the list would. Out-of-range indexes are ignored.

func (*Select) HoverColor

func (s *Select) HoverColor(c properties.Color) *Select

HoverColor sets the background of the option under the pointer. It returns s for chaining.

func (*Select) Layout

func (s *Select) Layout(gtx layout.Context) layout.Dimensions

Layout lays out the field and, when open, queues the dropdown panel as a portal (see elements.RegisterPortal) anchored just below it, so it paints above everything else regardless of where Layout is called from.

func (*Select) OnChange

func (s *Select) OnChange(fn func(index int)) *Select

OnChange sets the handler invoked when the selection changes. It returns s for chaining.

func (*Select) Opened

func (s *Select) Opened() bool

Opened reports whether the dropdown is open.

func (*Select) Options

func (s *Select) Options() []string

Options returns the selectable options.

func (*Select) Selected

func (s *Select) Selected() int

Selected returns the index of the selected option.

func (*Select) SetOptions

func (s *Select) SetOptions(options ...string)

SetOptions replaces the options. The selection stays on the same text when it's still among them, and otherwise moves to the first option; OnChange isn't called. An open list shows the new options.

func (*Select) SetSelected

func (s *Select) SetSelected(i int)

SetSelected changes the selection without invoking OnChange.

func (*Select) Sheet

func (s *Select) Sheet(m SheetMode) *Select

Sheet selects when the options open as a bottom sheet: a panel along the bottom edge of the window over a dimmed scrim, which closes when the scrim is tapped or Back is pressed. It returns s for chaining.

func (*Select) Value

func (s *Select) Value() string

Value returns the selected option's text.

type SheetMode

type SheetMode int

SheetMode selects when a Select shows its options as a bottom sheet rather than a list below the field.

const (
	// SheetNever always opens the list below the field (the default).
	SheetNever SheetMode = iota
	// SheetCompact opens a bottom sheet on compact screens: inside a
	// Responsive breakpoint named "compact" (see elements.Compact), or
	// in a window narrower than 600dp. This is the usual phone pattern
	// for pickers.
	SheetCompact
	// SheetAlways always opens a bottom sheet.
	SheetAlways
)

Jump to

Keyboard shortcuts

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