Inputs

Autogrow Textarea

A field that grows with its text: the layout itself computes the height from an invisible copy of the content, with no scrollHeight measuring and no jitter.

  • textarea
  • autogrow
  • grid
  • form

Preview

1440pxHost theme

Use it with AI

  1. 1. Copy the link.
  2. 2. Write to your agent in your own words and drop the link into the sentence.
  3. 3. The agent opens the link and installs the component from the registry.

put this in the header: https://vibeui.ru/c/textarea-003?lang=en

Grows as you type2 стр.

Show the full instructions

What the link says, spelled out. Use it when your agent cannot open links — paste this text instead.

# Install and place "textarea-003" (Autogrow Textarea) from VibeUI

## 1. Install first — do not skip, do not recreate
Run this exact command before writing any code:
npx shadcn@latest add https://vibeui.ru/r/textarea-003.json

Registry item: https://vibeui.ru/r/textarea-003.json
Installs to: components/vibeui/textarea-003.tsx (the exact path follows this project's components.json aliases).
npm dependencies: none.
Registry dependencies: none.

Install it from the registry. Do not recreate it from the description,
do not substitute a similar component from another library, and do not
rewrite it to match the project's existing style.

## 2. What it is
A field that grows with its text: the layout itself computes the height from an invisible copy of the content, with no scrollHeight measuring and no jitter.

An autogrowing field built on a grid text copy, with no height measuring. One file, zero dependencies, a client component.

## 3. How to use it
import { Textarea003 } from "@/components/vibeui/textarea-003"

<Textarea003
  label="Task for the team"
  rows={3}
/>

Read the installed file for the full prop list.

## 4. Where to place it
This is a small inline component. Put it exactly where the user asked,
inside the existing markup. Do not create a new page, section or
wrapper for it. If a similar control already sits in that spot,
replace it instead of adding a second one.

Placement: ___
(The user fills this line in. If it is still blank, ask where to put it
instead of guessing.)

## 5. Keep exactly as installed
- the local --vibeui-textarea-003-* palette — do not swap it for your theme tokens
- the grid-and-copy technique: measuring scrollHeight by hand causes jitter and an extra layout on every keystroke
- the trailing space in content:attr(data-value): without it a final empty line is ignored and the field stops growing
- the identical font and line-height on the copy and the field — otherwise the heights diverge and text is clipped
- overflow:hidden and resize:none on the textarea: a scrollbar inside a growing field makes no sense
- the component's own light surface — without it the dark text disappears on a dark page

## 6. You may change
- the caption through label and the placeholder text through placeholder
- the starting height through rows
- the line under the field through hint
- the accent colour through accent

## 7. Rules
- The field grows without limit: long text makes the card very tall — cap it with max-height if that matters.
- The text copy duplicates the content in an attribute: for very large texts that is extra markup weight.
- The border and focus ring live on the wrapper, not the textarea: put your own styles there too.
- Do not lift the CSS variables into globals.css: the component has to stay a single file.

## 8. Verify
- it renders with no console errors;
- it looks like the preview on the VibeUI page you copied this from;
- if it does not, you changed something listed in section 5 — put it back.

For developers

npx shadcn@latest add https://vibeui.ru/r/textarea-003.json
https://vibeui.ru/r/textarea-003.json

Клиентский компонент: useState хранит текст, который дублируется в data-value на обёртке. Обёртка — grid, textarea и псевдоэлемент ::after с content:attr(data-value) занимают одну ячейку, поэтому высота ячейки всегда равна высоте текста. Копия скрыта visibility:hidden и наследует шрифт и межстрочный интервал — иначе высоты разойдутся. Прокрутка у поля отключена, изменение размера мышью тоже. Палитра в --vibeui-textarea-003-*.

Component source

The same file your agent installs. Here in case you would rather copy it by hand.

"use client"

import { useId, useState } from "react"
import type { ComponentPropsWithoutRef, CSSProperties } from "react"

export type Textarea003Props = Omit<
  ComponentPropsWithoutRef<"div">,
  "children" | "onChange"
> & {
  label?: string
  placeholder?: string
  hint?: string
  /** Сколько строк поле занимает, пока пустое. */
  rows?: number
  accent?: string
}

// Идея компонента: поле, которое растёт под текст. Обычный способ —
// измерять scrollHeight и присваивать высоту вручную — даёт дрожание и
// лишний layout на каждом нажатии. Здесь высоту считает сама раскладка:
// обёртка — grid, в той же ячейке лежит невидимая копия текста через
// content:attr(), и textarea просто занимает всю высоту ячейки.
const STYLES = `
:where([data-vibeui-block="textarea-003"]){
--vibeui-textarea-003-bg:oklch(1 0 0);
--vibeui-textarea-003-fg:oklch(0.22 0.014 265);
--vibeui-textarea-003-muted:oklch(0.56 0.014 265);
--vibeui-textarea-003-border:oklch(0.9 0.006 265);
--vibeui-textarea-003-field:oklch(0.985 0.002 265);
--vibeui-textarea-003-accent:oklch(0.55 0.17 265);
--vibeui-textarea-003-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="textarea-003"]{
display:flex;flex-direction:column;gap:0.375rem;
width:100%;max-width:22rem;box-sizing:border-box;padding:0.875rem;
background:var(--vibeui-textarea-003-bg);
border:1px solid var(--vibeui-textarea-003-border);border-radius:0.875rem;
font-family:var(--vibeui-textarea-003-font);color:var(--vibeui-textarea-003-fg);
}
[data-vibeui-block="textarea-003"] label{font-size:0.8125rem;font-weight:600}
/* Обёртка и копия текста: обе занимают одну ячейку grid, поэтому высота
   ячейки всегда равна высоте текста — без измерений и без скачков. */
[data-vibeui-block="textarea-003"] [data-part="grow"]{
display:grid;box-sizing:border-box;
padding:0.5rem 0.75rem;
border:1px solid var(--vibeui-textarea-003-border);border-radius:0.625rem;
background:var(--vibeui-textarea-003-field);
font-size:0.875rem;line-height:1.55;
transition:border-color .16s ease,box-shadow .16s ease;
}
[data-vibeui-block="textarea-003"] [data-part="grow"]::after{
content:attr(data-value) " ";
grid-area:1 / 1 / 2 / 2;
visibility:hidden;white-space:pre-wrap;word-break:break-word;
font:inherit;
}
[data-vibeui-block="textarea-003"] textarea{
grid-area:1 / 1 / 2 / 2;
box-sizing:border-box;width:100%;
margin:0;padding:0;border:0;background:none;color:inherit;resize:none;overflow:hidden;
font:inherit;
}
[data-vibeui-block="textarea-003"] textarea:focus{outline:none}
[data-vibeui-block="textarea-003"] [data-part="grow"]:focus-within{
border-color:var(--vibeui-textarea-003-accent);
box-shadow:0 0 0 3px color-mix(in oklab,var(--vibeui-textarea-003-accent) 20%,transparent);
}
[data-vibeui-block="textarea-003"] [data-part="foot"]{
display:flex;align-items:baseline;justify-content:space-between;gap:0.5rem;margin:0;
font-size:0.75rem;color:var(--vibeui-textarea-003-muted);
}
[data-vibeui-block="textarea-003"] [data-part="lines"]{font-variant-numeric:tabular-nums}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="textarea-003"] *{animation:none!important;transition:none!important}}
`

const START =
  "Коротко о задаче: что делаем, для кого и к какому сроку.\nПоле растёт вместе с текстом — попробуйте добавить строку."

/**
 * Авторастущее поле: высоту считает grid по копии текста, без measure-хаков.
 * Один файл, ноль зависимостей, собственная палитра.
 */
export function Textarea003({
  label = "Задача для команды",
  placeholder = "Опишите задачу",
  hint = "Растёт по мере набора",
  rows = 2,
  accent,
  className,
  style,
  ...props
}: Textarea003Props) {
  const id = useId()
  const [value, setValue] = useState(START)

  const palette = {
    ...(accent ? { "--vibeui-textarea-003-accent": accent } : null),
    ...style,
  } as CSSProperties

  return (
    <>
      <style href="vibeui-textarea-003" precedence="medium">
        {STYLES}
      </style>
      <div
        {...props}
        data-vibeui-block="textarea-003"
        className={className}
        style={palette}
      >
        <label htmlFor={id}>{label}</label>
        <div data-part="grow" data-value={value}>
          <textarea
            id={id}
            rows={rows}
            value={value}
            placeholder={placeholder}
            onChange={(event) => setValue(event.target.value)}
          />
        </div>
        <p data-part="foot">
          <span>{hint}</span>
          <span data-part="lines">{value.split("\n").length} стр.</span>
        </p>
      </div>
    </>
  )
}