react-textarea-autosize

A drop-in <textarea> replacement for React that automatically grows and shrinks to fit its content.

Library
npm
v8.5.9
2,408stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
50/100Fair
Development Activity0
Maintenance32
Community68
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
65/100Good
Architecture78
Code Quality62
Innovation66
Learning Curve55

react-textarea-autosize is a lightweight React component that renders a native <textarea> and automatically resizes it as the user types, eliminating the need for manual scroll-height calculations or resize event wiring. It weighs about 1.3KB minified and gzipped, supports both controlled and uncontrolled usage, and exposes minRows/maxRows props to clamp growth within a bounded range.

Under the hood it measures the browser’s computed styles for font, padding, and border to calculate the exact pixel height needed for the current value, recalculating on window resize, form reset, and web font load so the textarea never looks broken during a page’s initial render.

What You Get

  • Drop-in <textarea> replacement - Accepts the same props as a native textarea, including value, onChange, and style, so migration requires no markup changes.
  • minRows/maxRows clamping - Bounds automatic growth between a minimum and maximum number of rows instead of growing without limit.
  • onHeightChange callback - Fires with the new pixel height and row height whenever the computed size changes, useful for syncing layout elsewhere on the page.
  • cacheMeasurements option - Reuses previously computed sizing data instead of re-reading computed styles on every keystroke, trading a small accuracy risk for performance.
  • Universal ref forwarding - Forwards a ref to the underlying textarea DOM node via forwardRef, so callers can still call .focus() or read .value directly.

Common Use Cases

  • Chat and comment composers - message boxes that grow as a user types a longer reply, then shrink back down when the field is cleared.
  • Form builders with free-text fields - dynamic forms where a description or notes field should never truncate content behind a fixed-height scrollbar.
  • Lightweight plain-text editors - editors that want auto-sizing behavior without pulling in a full code-editor dependency.
  • Admin/CMS content fields - backoffice tools where editors paste variable-length content and need the field to reflect the actual text length at a glance.

Under The Hood

Architecture Single-purpose React component library organized as a flat module set under src/: index.tsx (the main forwardRef component and resize orchestration), calculateNodeHeight.ts (pure height computation via a shared hidden shadow textarea), getSizingData.ts (reads computed style via window.getComputedStyle, filtered to a fixed SIZING_STYLE allowlist), hooks.ts (small event-listener hooks for window resize, document.fonts loadingdone, and form reset), forceHiddenStyles.ts (imperative style forcing on the shared measurement node), utils.ts (noop/pick helpers), and a conditions/ directory resolved via package.json’s conditional imports map to strip DOM-dependent code paths for edge/worker runtimes at build time. Data flow is one-directional and synchronous: a layout effect calls resizeTextarea() -> getSizingData(node) -> calculateNodeHeight(sizingData, value, minRows, maxRows) -> a direct node.style.setProperty call, guarded by a heightRef to skip redundant DOM writes. The module-level singleton hidden textarea in calculateNodeHeight.ts is shared across every mounted instance, a deliberate but tight coupling point that any refactor of that file needs to preserve.

Tech Stack TypeScript throughout, authored against React 16.8-19 as a peer dependency using hooks only. Exactly two runtime dependencies beyond @babel/runtime: use-composed-ref (merges the forwarded ref with the internal ref) and use-latest (keeps event listeners referencing the latest closure without re-subscribing). Built via @preconstruct/cli into CJS/ESM/edge-light/browser development and production variants declared through an elaborate conditional exports map, aimed at correct tree-shaking and runtime-specific behavior. Testing uses Jest, jsdom, and @testing-library/react; linting uses ESLint with husky and lint-staged for pre-commit enforcement; releases are managed with Changesets. A Vite-powered demo site lives in example/.

Code Quality A single test file covers only two rendering-snapshot cases (default render, and render with an initial height style) - no tests exercise resize behavior, minRows/maxRows clamping, or the height-calculation math directly, so behavioral coverage is thin despite CI running the suite on every push. Error handling is minimal but intentional: the component throws explicit, descriptive errors in development mode when a consumer passes disallowed style.maxHeight/minHeight props. Naming is consistent and descriptive, and types are precise apart from one narrow cast used for IE-only style assignment. ESLint, Prettier, and GitHub Actions CI enforce style and run tests automatically.

API Design The public API is a single default-exported forwardRef component that behaves as a true drop-in replacement for <textarea> - every native textarea prop passes through untouched, and only three opt-in props (minRows, maxRows, onHeightChange) plus a performance escape hatch (cacheMeasurements) are added, so adoption typically requires only an import-and-rename. It quietly handles the hard part - computed-style-based measurement, a documented Firefox double-set workaround, and both controlled and uncontrolled value semantics - without exposing that complexity in the props surface. Documentation is a single README with a props table and a short FAQ, adequate for its narrow scope.

Used by 28 apps in this directory

TypeScript
99%
Other

Activepieces

Automation · AI Assistants

24,298

Open-source AI automation platform that converts 280+ workflow integrations into MCP servers for LLMs, with no-code builders and TypeScript extensibility.

View details
92
Repo Health
85
Technical
64
Dependency
Built with
TypeScript99%
Updated today
Java
73%
Other

ByteChef

Automation · AI Agents

1,000

Unified open-source platform for AI agent orchestration and workflow automation with 180+ connectors, MCP support, and durable execution.

View details
85
Repo Health
82
Technical
70
Dependency
Built with
Java73%
TypeScript26%
Updated yesterday
TypeScript
98%
Apache 2.0

Cline

AI Code Assistants

67,585

An open-source AI coding agent that lives in your editor and terminal — reads and edits your codebase, runs commands, browses the web, and requires human approval for every action by default.

View details
89
Repo Health
74
Technical
65
Dependency
Built with
TypeScript98%
Updated 2 days ago
Go
75%
AGPL 3.0

Coder

Devops · Developer Tools · Code Editors

14,385

Self-hosted cloud development environments and AI coding agents — defined in Terraform, connected via WireGuard, automatically shut down when idle.

View details
93
Repo Health
90
Technical
68
Dependency
Built with
Go75%
TypeScript23%
Updated today
JavaScript
90%
Other

CodeSandbox

Code Editors · Developer Tools

13,640

Instantly ready browser-based IDE that runs full npm dependency resolution and transpilation entirely client-side, with no server needed.

View details
69
Repo Health
76
Technical
62
Dependency
Built with
JavaScript90%
Updated 1 weeks ago
TypeScript
50%
Other

Dify

No Code Platforms · AI Development · Developer Tools

154,649

Visual LLM workflow platform with RAG pipelines, agent capabilities, and model management for building production AI applications.

View details
92
Repo Health
85
Technical
67
Dependency
Built with
TypeScript50%
Python46%
Updated yesterday
TypeScript
100%
Other

Dub

Marketing · Analytics

24,676

The open-source link attribution platform for short links, conversion tracking, and affiliate programs — powering 100M+ clicks monthly.

View details
80
Repo Health
78
Technical
62
Dependency
Built with
TypeScript100%
Updated 2 days ago
TypeScript
89%
Other

FastGPT

AI Agents · AI Development

29,591

Build, debug, and deploy knowledge-based AI agents with a visual workflow editor, RAG retrieval, and support for any OpenAI-compatible LLM.

View details
93
Repo Health
84
Technical
69
Dependency
Built with
TypeScript89%
Updated yesterday
Go
65%
AGPL 3.0

Fider

Product Management · Customer Support

4,499

Open-source feedback portal where customers submit, vote on, and track feature requests so product teams build what actually matters.

View details
88
Repo Health
85
Technical
71
Dependency
Built with
Go65%
TypeScript29%
Updated 5 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search