InputMenu

输入搜索词并从候选项中选择。

实时预览

正在加载预览…

参数配置

全部字段 40

InputMenuItems

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

InputMenuOptions

Styles · 0
PopoverOptions
Styles · 0
列表项 · 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.InputMenu(c.Key("menu"), t, &s.Search, []nui.Option[string]{{Value: "go", Label: "Go"}, {Value: "rust", Label: "Rust"}, {Value: "typescript", Label: "TypeScript"}}, nui.InputMenuOptions{InputOptions: nui.InputOptions{Label: "Project name", Placeholder: "Type something…", Color: nui.ColorDefault, Size: nui.SizeDefault, Variant: nui.VariantDefault, Disabled: false, ReadOnly: false, Loading: false}, Multiple: false})

使用说明

在输入框搜索语言并选择候选项,切换 multiple 体验多选。InputMenu 的持久状态同时管理搜索与选择;不要在每次视图构建时创建新状态。

API 参考

InputMenu

源码
func InputMenu(c *ui.Context, t Theme, state *SearchState, options []Option[string], o InputMenuOptions) ui.Element

InputMenuOptions

源码
type InputMenuOptions struct {
	InputOptions
	EmptyText                                      string
	Popup                                          PopoverOptions
	AllowCustom                                    bool
	Multiple, ExternalFilter                       bool
	FilterFields                                   []string // label, description, value; nil uses label.
	Mode                                           InputMenuMode
	OpenOnClick, OpenOnFocus                       Optional[bool]
	ResetSearchTermOnBlur, ResetSearchTermOnSelect Optional[bool]
	OnValuesChange                                 func([]string)
	OnCreate                                       func(string)
	CreateWhenAlways                               bool
	CreateAtTop                                    bool
	OnSelect                                       func(string)
}
字段类型说明
Labelstring

Go 零值: ""

控件标签或可访问名称。

Placeholderstring

Go 零值: ""

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

ErrorMessagestring

Go 零值: ""

显式提供的错误说明。

Disabledbool

Go 零值: false

禁用组件及其交互。

ReadOnlybool

Go 零值: false

允许读取和选择内容,但禁止编辑。

Invalidbool

Go 零值: false

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

Passwordbool

Go 零值: false

遮蔽输入内容。

Clearablebool

Go 零值: false

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

ClearLabelstring

Go 零值: ""

清空操作的可访问名称。

ColorColor

Go 零值: ColorDefault

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

VariantVariant

Go 零值: VariantDefault

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

SizeSize

Go 零值: SizeDefault

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

Leading*ui.SVG

Go 零值: nil

内容前方的 SVG 图标。

Trailing*ui.SVG

Go 零值: nil

内容后方的 SVG 图标。

Loadingbool

Go 零值: false

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

LoadingIcon*ui.SVG

Go 零值: nil

覆盖默认加载图标。

Highlightbool

Go 零值: false

突出显示控件或选中项目。

MaxLengthint

Go 零值: 0

输入长度上限,原生文本以 UTF-16 单元计数;零表示不限。

OnChangefunc(string)

Go 零值: nil

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

OnSubmitfunc(string)

Go 零值: nil

提交表单或输入时通知应用的回调。

OnClearfunc()

Go 零值: nil

清空值时通知应用的回调。

UIStyles

Go 零值: zero value

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

Stylefunc(root, editor, leading, trailing ui.Element)

Go 零值: nil

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

EmptyTextstring

Go 零值: ""

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

PopupPopoverOptions

Go 零值: zero value

候选弹层的配置。

AllowCustombool

Go 零值: false

允许输入列表之外的值。

Multiplebool

Go 零值: false

允许选择多个项目。

ExternalFilterbool

Go 零值: false

由应用提供已筛选结果。

FilterFields[]string

Go 零值: nil

搜索时匹配的项目字段。

ModeInputMenuMode

Go 零值: zero value

组件行为模式或主题明暗模式。

OpenOnClickOptional[bool]

Go 零值: unset

点击输入框时打开候选列表。

OpenOnFocusOptional[bool]

Go 零值: unset

输入框获得焦点时打开候选列表。

ResetSearchTermOnBlurOptional[bool]

Go 零值: unset

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

ResetSearchTermOnSelectOptional[bool]

Go 零值: unset

选中项目后重置搜索词。

OnValuesChangefunc([]string)

Go 零值: nil

多选值变化时通知应用的回调。

OnCreatefunc(string)

Go 零值: nil

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

CreateWhenAlwaysbool

Go 零值: false

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

CreateAtTopbool

Go 零值: false

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

OnSelectfunc(string)

Go 零值: nil

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