HextaUI

Textarea: Character count

With maxLength inside a Field, FieldCounter counts as you type and nudges when you hit the limit.

import { Field, FieldCounter, FieldLabel } from "@/components/ui/field"
import { Textarea } from "@/components/ui/textarea"

export function TextareaCounter() {
  return (
    <Field className="w-full max-w-sm">
      <div className="flex items-baseline justify-between gap-3">
        <FieldLabel>Bio</FieldLabel>
        <FieldCounter />
      </div>
      <Textarea name="bio" maxLength={160} minRows={2} />
    </Field>
  )
}

This adds the example as components/examples/textarea/counter.tsx, together with the Textarea component and the HextaUI theme tokens it needs.

pnpm dlx shadcn@latest add https://hextaui.com/r/textarea-counter.json

To add only the component, follow the Textarea installation.

Props in this example

The Textarea props this example sets, from the API reference.

PropTypeDefault
minRows
number3

Every prop is in the Textarea API reference.

See them all, with keyboard support and accessibility notes, on the Textarea page.