Autosize Textarea
shadcn-htmx/autosize-textareaFreeComponent
Native <textarea> that grows/shrinks to fit its content between min/max bounds via the single CSS rule field-sizing: content — no scrollHeight JS hack. Degrades to a plain fixed field where unsupported; autosize={false} opts out to field-sizing: fixed. htmx autosave demo.
Live preview
live · rendered by the registry
Rendered by shadcn-htmx on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://shadcn-htmx.productdevbook.com/r/autosize-textarea.jsonSource
1/** @jsxImportSource hono/jsx */2import { cn, type ClassValue } from "@/registry/lib/cn"34// Autosize Textarea — a <textarea> that grows and shrinks to fit its content5// between min/max bounds, delivered by ONE CSS declaration instead of the6// classic scrollHeight JS hack. Source of truth for the platform behaviour:7// repos/mdn/files/en-us/web/css/reference/properties/field-sizing/index.md8// - "field-sizing: content overrides the default preferred sizing of form9// elements … configure text inputs to shrinkwrap their content and grow10// as more text is entered."11// - "<textarea> … If unable to grow due to a width constraint, they grow in12// height to display additional rows … When a height constraint is then13// reached, they show a scrollbar."14// - "rows/cols have no effect on <textarea> with field-sizing: content set."15// - "using min-height and max-height alongside field-sizing: content is16// quite effective … allow the control to grow and shrink … and prevent17// the control from becoming too large or too small."18// repos/mdn/files/en-us/web/html/reference/elements/textarea/index.md19// (native element, dirname, wrap, readonly/disabled semantics)20//21// Tailwind v4 ships the utility natively — see22// repos/tailwindcss/packages/tailwindcss/src/utilities.ts23// staticUtility('field-sizing-content', [['field-sizing','content']])24// staticUtility('field-sizing-fixed', [['field-sizing','fixed']])25//26// htmx attrs (hx-post / hx-trigger="input changed delay:…") verified against27// repos/htmx/www/reference.md (forwarded untouched via {...rest}).28//29// Style analogue: registry/ui/textarea.tsx (shares the base field styling).30//31// DEGRADATION: where field-sizing is unsupported, the rule is simply ignored32// and the element renders as an ordinary fixed-height textarea sized by33// min-height (and rows, which the browser then honours). No JS, no polyfill —34// progressive enhancement, not emulation. Pass autosize={false} to opt out35// explicitly (field-sizing-fixed), turning it into a plain bounded textarea.3637// Bounds are expressed as utilities so a single CSS line drives the resize.38// Defaults: grow from ~2 lines up to ~10 lines, then scroll.39const base =40 "flex w-full rounded-md border border-input bg-transparent px-3 py-2 text-base shadow-xs transition-[color,box-shadow] outline-none " +41 "placeholder:text-muted-foreground " +42// … truncated
More from shadcn-htmx
All 83 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | shadcn-htmx | Components | Free | no deps | |
| Active Searchactive-search | shadcn-htmx | Components | Free | no deps | |
| Alertalert | shadcn-htmx | Components | Free | no deps | |
| Alert Dialogalert-dialog | shadcn-htmx | Components | Free | no deps | |
| Aspect Ratioaspect-ratio | shadcn-htmx | Components | Free | no deps | |
| Auto Gridauto-grid | shadcn-htmx | Components | Free | no deps | |
| Autocompleteautocomplete | shadcn-htmx | Components | Free | no deps | |
| Avataravatar | shadcn-htmx | Components | Free | no deps |
