Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Input Group examples · Text

Character Counter Input Group (Text) for React

A tweet input with a 280-character limit shown at its end.

Framework
UI library

A single-line post field with its limit in view: 0/280 sits at the end of the input in an InputGroupText, and maxLength stops typing at 280.

Preview

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

FAQ

What enforces the limit?

maxLength={280} on InputGroupInput.

Does 0/280 count as people type?

No, it's fixed text. Keep the value in state and render its length.

How does the count sit at the end?

An InputGroupAddon with align="inline-end", after the input.

How do I warn near the limit?

Switch the count to text-destructive past a threshold, from the same state.

Do screen readers hear the count?

Not unless you tie it in: give the count an id and set aria-describedby on the input.

How is the input labeled?

aria-label="Tweet".