Select
从类型化选项中选择单个或多个值。
实时预览
正在加载预览…
参数配置
全部字段 26
SelectItems
列表项 · 3
Option[string]
Option[string]
Option[string]
SelectOptions
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.ElementSelectMultiple
源码func SelectMultiple[T comparable](c *ui.Context, t Theme, value *[]T, options []Option[T], o SelectOptions) ui.ElementSelectOptions
源码type SelectOptions struct {
Label, Placeholder, ErrorMessage string
Disabled, Invalid bool
Color Color
Variant Variant
Size Size
Popup PopoverOptions
OnChange func()
Decoration
}| 字段 | 类型 | 说明 |
|---|---|---|
Label | stringGo 零值: | 控件标签或可访问名称。 |
Placeholder | stringGo 零值: | 没有输入或选择时的占位文字。 |
ErrorMessage | stringGo 零值: | 显式提供的错误说明。 |
Disabled | boolGo 零值: | 禁用组件及其交互。 |
Invalid | boolGo 零值: | 使用无效输入的视觉状态。 |
Color | ColorGo 零值: | 语义颜色;默认值继承主题或组件配色。 |
Variant | VariantGo 零值: | 组件外观样式,支持范围取决于组件。 |
Size | SizeGo 零值: | 组件尺寸;默认值继承主题或组件尺寸。 |
Popup | PopoverOptionsGo 零值: | 候选弹层的配置。 |
OnChange | func()Go 零值: | 值发生变化时通知应用的回调。 |
UI | StylesGo 零值: | 以部件名称为键覆盖外观和间距。 |
Style | func(Slot, ui.Element)Go 零值: | 同步配置当前构建的部件;不要保留 Element。 |