Input

编辑单行文字并保留输入状态。

实时预览

正在加载预览…

参数配置

全部字段 23

InputOptions

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.Input(c.Key("input"), t, &s.Value, nui.InputOptions{Label: "Project name", Placeholder: "Type something…", Color: nui.ColorDefault, Size: nui.SizeDefault, Variant: nui.VariantDefault, Disabled: false, ReadOnly: false, Loading: false})
ui.Textf(c, "Value: %s", s.Value)

使用说明

在预览中输入内容,再修改尺寸、主题或语言,已输入的文字会保留。ReadOnly 允许读取但禁止编辑,Disabled 用于禁用控件;完整示例把字符串状态保存在视图外。

API 参考

Input

源码
func Input(c *ui.Context, t Theme, value *string, o InputOptions) ui.Element

InputOptions

源码
type InputOptions struct {
	Label, Placeholder, ErrorMessage                 string
	Disabled, ReadOnly, Invalid, Password, Clearable bool
	ClearLabel                                       string
	Color                                            Color
	Variant                                          Variant
	Size                                             Size
	Leading, Trailing                                *ui.SVG
	Loading                                          bool
	LoadingIcon                                      *ui.SVG
	Highlight                                        bool
	MaxLength                                        int // UTF-16 units; 0 is unlimited.
	OnChange, OnSubmit                               func(string)
	OnClear                                          func()
	UI                                               Styles
	// Style receives current-build parts; editor is where handles and editing actions bind.
	Style func(root, editor, leading, trailing ui.Element)
	// contains filtered or unexported fields
}
字段类型说明
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。