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,413 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
50 /100 Fair
Development Activity 0
Maintenance 32
Community 68
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
65 /100 Good
Architecture 78
Code Quality 62
Innovation 66
Learning Curve 55

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%
AGPL 3.0

fountain-ink

Blogging

64

A self-hostable, decentralized blogging platform built on Lens Protocol — own your content, audience, and distribution forever.

View details
26
Repo Health
66
Technical
63
Dependency
Built with
TypeScript 99%
Updated 8 months ago
TypeScript
98%
Other

GrowthBook

Ab Testing Experimentation · Analytics · Developer Tools

8,527

Open source feature flags, A/B testing, and warehouse-native experimentation that queries your existing data infrastructure—no data movement required.

View details
92
Repo Health
85
Technical
63
Dependency
Built with
TypeScript 98%
Updated 5 days ago
TypeScript
95%
AGPL 3.0

HeyForm

Forms Surveys · No Code Platforms

9,048

Open-source conversational form builder with AI generation, conditional logic, and 30+ integrations — self-host with full data ownership.

View details
86
Repo Health
67
Technical
67
Dependency
Built with
TypeScript 95%
Updated 5 days ago
TypeScript
99%
MIT

GraphQL Hive

Developer Tools · Devops · Monitoring

483

Open-source GraphQL schema registry and observability platform with breaking change detection, federation support, and CI/CD integration for teams of any size.

View details
90
Repo Health
81
Technical
68
Dependency
Built with
TypeScript 99%
Updated 6 days ago
Rust
56%
Other

Jan

AI Assistants

45,052

Run LLMs 100% locally with full privacy, or connect to cloud AI — your machine, your data, your control.

View details
90
Repo Health
81
Technical
65
Dependency
Built with
Rust 56%
TypeScript 40%
Updated 5 days ago
TypeScript
73%
Apache 2.0

Jitsi Meet

Collaboration · Team Chat · Video Conferencing

30,130

Open-source, end-to-end encrypted video conferencing you can self-host or embed into any web or mobile app.

View details
96
Repo Health
85
Technical
67
Dependency
Built with
TypeScript 73%
Lua 11%
JavaScript 10%
Updated 6 days ago
TypeScript
63%
Apache 2.0

Laminar

AI Development · Monitoring

3,434

Open-source observability platform purpose-built for AI agents — trace, evaluate, debug, and monitor at scale with SQL access and real-time replay.

View details
86
Repo Health
76
Technical
65
Dependency
Built with
TypeScript 63%
Rust 35%
Updated 5 days ago
TypeScript
78%
LGPL 3.0

Latitude

AI Agents · Monitoring

4,733

Open-source AI agent monitoring that catches what will break next before your users do.

View details
87
Repo Health
88
Technical
67
Dependency
Built with
TypeScript 78%
Python 11%
Rust 11%
Updated 6 days ago
TypeScript
85%
MIT

LibreChat

AI Assistants · Developer Tools

46,236

Unite every major AI model in one self-hosted chat platform with agents, code execution, MCP tools, and enterprise authentication.

View details
93
Repo Health
81
Technical
62
Dependency
Built with
TypeScript 85%
JavaScript 14%
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