SelectMenu

在可搜索的弹出列表中选择项目。

实时预览

正在加载预览…

参数配置

全部字段 36

SelectMenuItems

列表项 · 3
ListboxItem
ListboxItem
ListboxItem

SelectMenuOptions

Styles · 0
列表项 · 0
PopoverOptions
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.SelectMenu(c.Key("select"), t, &s.Values, &s.Menu, []nui.ListboxItem{{ID: "go", Label: "Go", Description: "Native applications"}, {ID: "rust", Label: "Rust", Description: "Systems programming"}, {ID: "typescript", Label: "TypeScript", Description: "Web applications"}}, nui.SelectMenuOptions{ListboxOptions: nui.ListboxOptions{Label: "Languages", Multiple: false, Disabled: false}, Placeholder: "Type something…", SearchInput: nui.Optional[bool]{}, Clearable: true, Loading: false, Color: nui.ColorDefault, Size: nui.SizeDefault, Variant: nui.VariantDefault})

使用说明

展开菜单搜索并选择语言,试试多选、搜索开关和加载状态。示例同时保存所选 ID 与 SelectMenu 状态;清空操作不会重新创建选项数据。

API 参考

SelectMenu

源码
func SelectMenu(c *ui.Context, t Theme, value *[]string, s *SelectMenuState, items []ListboxItem, o SelectMenuOptions) ui.Element

SelectMenuOptions

源码
type SelectMenuOptions struct {
	ListboxOptions
	Color                                          Color
	Variant                                        Variant
	Size                                           Size
	SearchInput                                    Optional[bool]
	ResetSearchTermOnBlur, ResetSearchTermOnSelect Optional[bool]
	Placeholder                                    string
	Invalid                                        bool
	ErrorMessage                                   string
	SearchPlaceholder                              string
	Clearable, Loading, ExternalFilter             bool
	Error                                          string
	OnQuery                                        func(string)
	OnCreate                                       func(string)
	FilterFields                                   []string // label (default), description, value/id, group.
	CreateWhenAlways, CreateAtTop                  bool
	Popup                                          PopoverOptions
}
字段类型说明
Buildfunc(*ui.Context, Theme, ListboxItem)

Go 零值: nil

同步构建当前项目的视觉内容。

Labelstring

Go 零值: ""

控件标签或可访问名称。

EmptyTextstring

Go 零值: ""

没有可显示数据时的文案。

Multiplebool

Go 零值: false

允许选择多个项目。

Disabledbool

Go 零值: false

禁用组件及其交互。

Heightfloat32

Go 零值: 0

高度,单位为 DIP。

OrientationOptional[Orientation]

Go 零值: unset

水平或垂直方向;未设置时使用组件默认方向。

ItemWidthfloat32

Go 零值: 0

横向列表项的宽度。

Loopbool

Go 零值: false

键盘导航到边界时循环。

HighlightOnHoverOptional[bool]

Go 零值: unset

悬停时高亮列表项。

SelectionBehaviorSelectionBehavior

Go 零值: zero value

控制列表选择的切换或替换策略。

OnChangefunc([]string)

Go 零值: nil

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

OnSelectfunc(string)

Go 零值: nil

激活或选择项目时通知应用的回调。

UIStyles

Go 零值: zero value

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

Stylefunc(Slot, ui.Element)

Go 零值: nil

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

ColorColor

Go 零值: ColorDefault

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

VariantVariant

Go 零值: VariantDefault

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

SizeSize

Go 零值: SizeDefault

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

SearchInputOptional[bool]

Go 零值: unset

是否显示搜索框;未设置时使用组件默认策略。

ResetSearchTermOnBlurOptional[bool]

Go 零值: unset

关闭或失焦时重置搜索词。

ResetSearchTermOnSelectOptional[bool]

Go 零值: unset

选中项目后重置搜索词。

Placeholderstring

Go 零值: ""

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

Invalidbool

Go 零值: false

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

ErrorMessagestring

Go 零值: ""

显式提供的错误说明。

SearchPlaceholderstring

Go 零值: ""

搜索输入框的占位文字。

Clearablebool

Go 零值: false

显示清空操作或允许清除当前值。

Loadingbool

Go 零值: false

显示加载状态;是否阻止操作由组件决定。

ExternalFilterbool

Go 零值: false

由应用提供已筛选结果。

Errorstring

Go 零值: ""

错误状态或错误说明。

OnQueryfunc(string)

Go 零值: nil

搜索词变化时通知应用的回调。

OnCreatefunc(string)

Go 零值: nil

请求创建项目时通知应用的回调。

FilterFields[]string

Go 零值: nil

搜索时匹配的项目字段。

CreateWhenAlwaysbool

Go 零值: false

即使存在匹配项也提供创建操作。

CreateAtTopbool

Go 零值: false

将创建操作放在候选列表顶部。

PopupPopoverOptions

Go 零值: zero value

候选弹层的配置。