---
title: "Textarea 组件 — zenit Zig UI"
description: "多行编辑，支持 helper、error 和禁用态。换行、选区、滚动、字素边界、IME preedit / commit 与单行输入保持一致。"
url: https://zenit.z.express/zh/components/textarea
language: zh-CN
alternate_en: https://zenit.z.express/components/textarea.md
alternate_es: https://zenit.z.express/es/components/textarea.md
alternate_ja: https://zenit.z.express/ja/components/textarea.md
alternate_ko: https://zenit.z.express/ko/components/textarea.md
alternate_fr: https://zenit.z.express/fr/components/textarea.md
alternate_de: https://zenit.z.express/de/components/textarea.md
project: zenit v0.1.0-alpha (Zig 0.15.2, macOS)
source: https://github.com/version-next/zenit
---

# Textarea

`ui.widgets.Textarea`

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

[Video](https://zenit.z.express/media/stories/textarea.mp4?v=01136a4b5d)

**BEHAVIOR CONTRACT**

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

**RECORDED INTERACTION**

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

`examples/storybook/stories.zig:2923`

```zig
// ── 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](https://github.com/version-next/zenit/blob/HEAD/examples/storybook/stories.zig#L2923)

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

### TextareaProps

`ui.widgets.Textarea`

[src/ui/components/input/textarea.zig:2092](https://github.com/version-next/zenit/blob/HEAD/src/ui/components/input/textarea.zig#L2092)

```zig
fn Textarea(props: TextareaProps) TextareaBuilder
```

| 字段 | 类型 | 默认值 | 说明 |
| --- | --- | --- | --- |
| `value` | `?[]const u8` | `null` | — |
| `placeholder` | `?[]const u8` | `null` | — |
| `label_text` | `?[]const u8` | `null` | — |
| `helper` | `?[]const u8` | `null` | — |
| `error_msg` | `?[]const u8` | `null` | — |
| `rows` | `u32` | `4` | — |
| `disabled` | `bool` | `false` | — |
| `required` | `bool` | `false` | — |
| `readonly` | `bool` | `false` | — |
| `width` | `?f32` | `null` | — |
| `on_change` | `?core_ui.HandlerRef` | `null` | — |
| `context` | `?*anyopaque` | `null` | — |

### \*Node

`ui.widgets.Textarea`

mount 直接返回 `*Node`，把它 append 到父节点即可。
