The resize effect our textarea didn't need
How we removed a textarea resize effect and kept the behavior with field-sizing, a minimum height, and a maximum height.
Audrey KlammerCSSshadcn
Our chat composer had a React effect with one job: resize the textarea
after every edit. Reset its height, measure scrollHeight, then write a
new height.
The Textarea underneath already supported growing with its content.
We removed the effect and its ref, added a maximum height, and let CSS handle the resizing.
Try typing or pasting below. Add a few lines, reach the height limit, then clear the field to watch it shrink.
Type, paste, or add sample lines. Clear the field to start again.
The code we removed
This was the resize loop in our chat composer:
React.useEffect(() => {
const node = ref.current
if (!node) return
node.style.height = "0px"
node.style.height = `${Math.min(node.scrollHeight, 144)}px`
}, [value])
shadcn's Base UI Textarea already has field-sizing-content in its class list
(textarea.tsx, line 9).
InputGroupTextarea, which chat composers use, renders that same Textarea
(input-group.tsx, lines 129 to 140).
Our effect was setting an explicit height on a control that could size
itself from its content.
Reading scrollHeight after changing the height can also force the
browser to calculate layout immediately. Removing the effect removes that
write-then-measure loop
(web.dev on forced synchronous layout).
The replacement
Delete the effect and its resize-only ref. Keep the starting height and the limit in CSS:
<InputGroup>
<InputGroupTextarea
rows={1}
className="field-sizing-content max-h-36 min-h-11 py-2.5 text-sm/6"
/>
</InputGroup>
Each sizing class has a job:
field-sizing-contentlets the textarea size itself from its text. It is already in the current stock part; spelling it out also covers an older installed copy that lacks the class.min-h-11sets the starting height: 44px with Tailwind's default spacing and a 16px root font size.max-h-36caps it at 144px with those defaults, matching the old effect. More text stays accessible by scrolling inside the field.
MDN describes how content sizing works with size limits.
A fixed height overrides content-driven height; minimum and maximum
heights let it grow within bounds.
What we measured
In our Chromium test of the chat composer, with its typography and spacing, we measured:
| Text in the field | Height | Behavior |
|---|---|---|
| Empty | 44px | Starting height |
| Three lines | 92px | Grows with the text |
| Ten lines | 144px | Stops growing and scrolls |
| Cleared | 44px | Returns to the starting height |
These are measurements of that component, not universal textarea sizes.
Before removing your effect
In browsers supporting content sizing, rows and cols no longer set
the textarea's size
(MDN).
MDN marks field-sizing as
Baseline 2026, available across current major browsers since June 2026.
Older browsers ignore the property. The field stays at the height
determined by rows and its CSS sizing constraints, and scrolls as text
is added. If those browsers also need automatic growth, retain a fallback
for them.
Before adding a resize effect, inspect the textarea's existing styles:
field-sizing, an explicit height, and its minimum and maximum heights.