Select

从类型化选项中选择单个或多个值。

实时预览

正在加载预览…

参数配置

全部字段 26

SelectItems

列表项 · 3
Option[string]
Option[string]
Option[string]

SelectOptions

PopoverOptions
Styles · 0
Styles · 0

SelectMultipleItems

列表项 · 3
Option[string]
Option[string]
Option[string]

SelectOptions2

PopoverOptions
Styles · 0
Styles · 0

Go 代码

Go
// Inside a view; c is *ui.Context, t is nui.Theme.
// Keep s (example state) outside the view. See the complete example.
nui.Select(c.Key("select"), t, &s.Value, []nui.Option[string]{{Value: "go", Label: "Go"}, {Value: "rust", Label: "Rust"}, {Value: "typescript", Label: "TypeScript"}}, nui.SelectOptions{Label: "Language", Placeholder: "Type something…", Color: nui.ColorDefault, Size: nui.SizeDefault, Variant: nui.VariantDefault, Disabled: false})
ui.Textf(c, "Selected: %s", s.Value)
nui.SelectMultiple(c.Key("multiple"), t, &s.Many, []nui.Option[string]{{Value: "go", Label: "Go"}, {Value: "rust", Label: "Rust"}, {Value: "typescript", Label: "TypeScript"}}, nui.SelectOptions{Label: "Multiple languages", Placeholder: "Select several", Color: nui.ColorDefault, Size: nui.SizeDefault, Variant: nui.VariantDefault, Disabled: false})

使用说明

上方是单选,下方 SelectMultiple 是多选。展开后用鼠标或方向键选择语言,修改尺寸与样式时选择保持不变;Option.Value 与显示标签分开管理。

API 参考

Select

源码
func Select[T comparable](c *ui.Context, t Theme, selected *T, options []Option[T], o SelectOptions) ui.Element

SelectMultiple

源码
func SelectMultiple[T comparable](c *ui.Context, t Theme, value *[]T, options []Option[T], o SelectOptions) ui.Element

SelectOptions

源码
type SelectOptions struct {
	Label, Placeholder, ErrorMessage string
	Disabled, Invalid                bool
	Color                            Color
	Variant                          Variant
	Size                             Size
	Popup                            PopoverOptions
	OnChange                         func()
	Decoration
}
字段类型说明
Labelstring

Go 零值: ""

控件标签或可访问名称。

Placeholderstring

Go 零值: ""

没有输入或选择时的占位文字。

ErrorMessagestring

Go 零值: ""

显式提供的错误说明。

Disabledbool

Go 零值: false

禁用组件及其交互。

Invalidbool

Go 零值: false

使用无效输入的视觉状态。

ColorColor

Go 零值: ColorDefault

语义颜色;默认值继承主题或组件配色。

VariantVariant

Go 零值: VariantDefault

组件外观样式,支持范围取决于组件。

SizeSize

Go 零值: SizeDefault

组件尺寸;默认值继承主题或组件尺寸。

PopupPopoverOptions

Go 零值: zero value

候选弹层的配置。

OnChangefunc()

Go 零值: nil

值发生变化时通知应用的回调。

UIStyles

Go 零值: zero value

以部件名称为键覆盖外观和间距。

Stylefunc(Slot, ui.Element)

Go 零值: nil

同步配置当前构建的部件;不要保留 Element。