Textarea
编辑多行内容并可自动调整高度。
实时预览
参数配置
全部字段 26
TextareaOptions
Go 代码
// Inside a view; c is *ui.Context, t is nui.Theme.
// Keep s (example state) outside the view. See the complete example.
nui.Textarea(c.Key("textarea"), t, &s.Value, nui.TextareaOptions{InputOptions: nui.InputOptions{Label: "Project name", Placeholder: "Type something…", Color: nui.ColorDefault, Size: nui.SizeDefault, Variant: nui.VariantDefault, Disabled: false, ReadOnly: false, Loading: false}, Rows: 3, AutoResize: true})使用说明
输入多行文字并比较 Rows 与 AutoResize。Textarea 复用 InputOptions,文本状态需要在重建之间持久保存;增加行数不会重新初始化内容。
API 参考
Textarea
源码func Textarea(c *ui.Context, t Theme, value *string, o TextareaOptions) ui.ElementTextareaOptions
源码type TextareaOptions struct {
InputOptions
Rows, MaxRows int
AutoResize bool
}| 字段 | 类型 | 说明 |
|---|---|---|
Label | stringGo 零值: | 控件标签或可访问名称。 |
Placeholder | stringGo 零值: | 没有输入或选择时的占位文字。 |
ErrorMessage | stringGo 零值: | 显式提供的错误说明。 |
Disabled | boolGo 零值: | 禁用组件及其交互。 |
ReadOnly | boolGo 零值: | 允许读取和选择内容,但禁止编辑。 |
Invalid | boolGo 零值: | 使用无效输入的视觉状态。 |
Password | boolGo 零值: | 遮蔽输入内容。 |
Clearable | boolGo 零值: | 显示清空操作或允许清除当前值。 |
ClearLabel | stringGo 零值: | 清空操作的可访问名称。 |
Color | ColorGo 零值: | 语义颜色;默认值继承主题或组件配色。 |
Variant | VariantGo 零值: | 组件外观样式,支持范围取决于组件。 |
Size | SizeGo 零值: | 组件尺寸;默认值继承主题或组件尺寸。 |
Leading | *ui.SVGGo 零值: | 内容前方的 SVG 图标。 |
Trailing | *ui.SVGGo 零值: | 内容后方的 SVG 图标。 |
Loading | boolGo 零值: | 显示加载状态;是否阻止操作由组件决定。 |
LoadingIcon | *ui.SVGGo 零值: | 覆盖默认加载图标。 |
Highlight | boolGo 零值: | 突出显示控件或选中项目。 |
MaxLength | intGo 零值: | 输入长度上限,原生文本以 UTF-16 单元计数;零表示不限。 |
OnChange | func(string)Go 零值: | 值发生变化时通知应用的回调。 |
OnSubmit | func(string)Go 零值: | 提交表单或输入时通知应用的回调。 |
OnClear | func()Go 零值: | 清空值时通知应用的回调。 |
UI | StylesGo 零值: | 以部件名称为键覆盖外观和间距。 |
Style | func(root, editor, leading, trailing ui.Element)Go 零值: | 同步配置当前构建的部件;不要保留 Element。 |
Rows | intGo 零值: | 初始显示的文本行数。 |
MaxRows | intGo 零值: | 自动调整高度时的最大行数。 |
AutoResize | boolGo 零值: | 随内容自动调整文本域高度。 |