组件

Textarea

A multi-line text field on paper: a pencil box around a real <textarea> that grows with its text, with optional hand-ruled lines on the baselines, a drawn resize handle and a character counter.

安装

terminal
npx shadcn@latest add @wobko/textarea

第一次使用?先把 registry 加进 components.json。 如何安装

示例

Default

Grows with what you write. The resize handle in the corner is drawn by hand over the browser's own.

Ruled paper

ruled draws pencil lines on the baselines of the text. The rules are re-pulled as the box grows, so they always end where the paper does.

Counter and states

showCount with maxLength; the second field turns red when it is too short. Disabled and read-only fields are drawn as such.

A feedback form

Label, Input and a ruled Textarea in a real form: the note is required, and the button says what happened.

Demo

Official `textarea-demo`: a bare textarea with a placeholder. It sits in a hand-drawn box that grows with its text (`field-sizing: content`, as upstream) and redraws the resize grip in its corner. Only addition: an `aria-label`, since there is no visible label.

Disabled

Official `textarea-disabled`: the same field with `disabled`. The box is redrawn dashed in pencil gray, so the state does not rest on color alone.

With button

Official `textarea-with-button`: the field stacked over a full-width Send button on a two-row grid. The gap is `gap-3` (the original's `gap-2` plus a pencil's width): a marker band bleeds a few pixels past its box, and a wide one would touch the field.

With label

Official `textarea-with-label`: a Label tied to the field by `htmlFor` and `id`, so a click on the words puts the cursor in the box. The id is prefixed to stay unique on a page with other examples.

With text

Official `textarea-with-text`: a label, the field and a line of help text below. The help is linked to the field with `aria-describedby` (the original leaves it unlinked), so a screen reader reads it with the field.

API 参考

Textarea

A <span data-slot="textarea-frame"> (the drawn box) around <textarea data-slot="textarea">. As with Input, every prop and ref go to the <textarea>; className and style go to the frame, and padding, resize-* and control variants (placeholder:, focus:, ...) are moved onto the textarea.

属性类型默认值说明
classNamestring-Classes for the frame (width, min/max height, margins, font, text color). Padding, resize-*, field-sizing-* and control-only variants are applied to the <textarea>.
inputClassNamestring-Classes appended to the <textarea> itself.
ruledbooleanfalseHand-ruled paper: pencilled rules on the text's baselines. It fixes the rhythm (28 px lines, the first 8 px from the top, min height of three lines) and always grows with its text, so lines and text never drift apart.
autoGrowbooleantrueGrow with the text using field-sizing: content, as upstream does. false keeps rows and a fixed height.
showCountboolean | (info: { length: number; max?: number }) => ReactNodefalseA counter in the bottom corner (12 or 12/280 with maxLength), or your own render function. It is the field's aria-describedby, so a screen reader hears it on focus, not on every keystroke.
seedstring | number-Pins the hand: the same seed always draws the same box. Default: derived from useId().
aria-invalidboolean | "true" | "false"-true draws the red-pencil box, the wavy underline and a ! in the corner.
disabled / readOnlyboolean-Dashed pencil on a pale wash / a printed field.

无障碍

  • A native <textarea>: Enter adds a line, Tab moves on, and label / aria-describedby / required work as usual.
  • aria-invalid, disabled and readOnly are the real attributes; the drawing follows them.
  • Focus draws the blue felt ring; the browser's outline is used before the drawing exists and in Windows high contrast.
  • The counter is aria-describedby text ("12 characters of 280"), never a live region.
  • Resizing uses the browser's own handle (made transparent and redrawn by hand), so it keeps working with the mouse and touch.
  • field-sizing: content needs a current browser; elsewhere the textarea keeps its rows and scrolls.

源码

CLI 会复制进你项目的文件。

正在加载源码