components/textarea
输入与表单 · 09 / 64

Textarea

ui.widgets.Textarea

多行编辑,支持 helper、error 和禁用态。

BEHAVIOR CONTRACT

换行、选区、滚动、字素边界、IME preedit / commit 与单行输入保持一致。

RECORDED INTERACTION

Harness 聚焦文本框并写入两行内容。

examples/storybook/stories.zig:2923
// ── Textarea ──
pub fn buildTextarea(scope: *ui.Scope, cx: *ui.Cx) anyerror!*ui.Node {
    const a = cx.allocator;
    const c = try col(cx, 12);

    const ta = try W.Textarea(.{ .label_text = "Notes", .placeholder = "Write something…", .rows = 5, .width = 420 }).mount(scope, cx);
    ta.meta.ownership.meta.test_id = "story.textarea.box";
    try c.appendChild(a, ta);

    try c.appendChild(a, try W.Textarea(.{ .label_text = "With helper", .placeholder = "Bio", .helper = "Max 500 characters", .rows = 3, .width = 420 }).mount(scope, cx));
    try c.appendChild(a, try W.Textarea(.{ .label_text = "With error", .value = "too short", .error_msg = "Please write more", .rows = 3, .width = 420 }).mount(scope, cx));
    try c.appendChild(a, try W.Textarea(.{ .label_text = "Disabled", .placeholder = "Cannot edit", .disabled = true, .rows = 3, .width = 420 }).mount(scope, cx));
    return c;
}
在 GitHub 查看源码examples/storybook/stories.zig:2923

这是 Storybook 中该 story 的原样代码(zenit 5f9add5+wip 2026-09-30)。其中 W 即 ui.widgets,col / row / label 是 Storybook 内的布局小工具。

zenit · 双授权开源项目可按 GPL-3.0-only 免费使用;闭源或商业产品需要商业授权。可联系作者:zongyi.xzy#gmail.com(# 换成 @)zenit 5f9add5+wip 2026-09-30