Skip to content
Pebble Pro is here at $49 one timeSee what’s included ↗
Pebble
ComponentsDocsMCPPricing
⌕ Find a component↗Log in
All components 673

Categories

Core inputs & forms46Buttons & actions33Navigation36Overlays & feedback49Data display33Charts & data viz40Cards & layout43Marketing blocks38App shells & pages37AI interfaces40Text & typography effects33Backgrounds & visual effects38Motion & transitions32Numbers & counters32Media34E-commerce333D & interactive36Themed sets40
Start with the essentials.Installation guide ↗Connect your agent ↗
← All componentsCore inputs & forms

Textarea

A multi-line text input that grows with its content.

Preview

MO

Malik Osei

Asked for feedback on the export redesign

138 / 280142 characters left

Add a sentence so Priya knows what to announce.

45 / 483 characters left

Install

Add the editable source with the shadcn CLI. Your project also needs the shared theme tokens this component uses. Setup and requirements. The Pebble installer is not published yet.

npx shadcn@latest add https://pebbleui.com/r/textarea.json

Props

PropTypeDefaultDescription
showCountbooleanfalseCharacter count in the corner; with maxLength it shows used / limit and warns near it
rootClassNamestring—Classes for the wrapper rendered when showCount is on
aria-invalidboolean—Danger border and ring
disabledbooleanfalseNot interactive, 50% opacity
...propsReact.ComponentProps<"textarea">—All native textarea props
Build notes
`field-sizing: content` (Tailwind `field-sizing-content`) lets the browser
size the box to its text with no JS measuring. Browsers without support fall
back to an ordinary textarea at `min-h-16`, still resizable by the user. No
state, so no `"use client"`.

**Pebble (2026-11-03).** Same recessed well as Text Field (card fill, `border-control`, inner shade, ring-offset focus, muted disabled fill). Added optional `showCount` and `rootClassName`: the length is mirrored from `defaultValue` and `onChange` when uncontrolled and read from `value` when controlled. The counter is `tabular-nums`, `aria-hidden`, placed clear of the resize grip, and moves through `normal`, `near` (last tenth of `maxLength`, warning) and `limit` (danger) via `data-state`. That length mirror is state, so the file is now `"use client"`. A polite live region announces the remaining count only as it crosses a threshold (entering `near`, 10, 5, 0), so typing is not narrated key by key.

<!-- PEBBLE-LICENSE -->
View source

registry/input/textarea/textarea.tsx

"use client";

/* PEBBLE-LICENSE
Built by Pebble. Component: textarea.

First-party license: MIT

The following first-party terms apply only to original Pebble material.

MIT License

Copyright (c) 2026 Praxys Solutions LLC (Pebble)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

THIRD-PARTY NOTICES
These notices apply to identified upstream portions; Pebble terms do not replace or narrow their rights.

Upstream: https://raw.githubusercontent.com/shadcn-ui/ui/main/LICENSE.md
MIT License

Copyright (c) 2023 shadcn

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
END PEBBLE-LICENSE */

import * as React from "react";

import { cn } from "@/lib/utils";

export type TextareaProps = React.ComponentProps<"textarea"> & {
  /**
   * Show a character count in the bottom corner. With `maxLength` it reads
   * "120 / 280", turns amber in the last tenth and red at the limit.
   */
  showCount?: boolean;
  /** Classes for the wrapper rendered when `showCount` is set. */
  rootClassName?: string;
};

const fieldClasses = [
  // field-sizing: content grows the box with its text; browsers without
  // it fall back to a normal resizable textarea at min-h-16. A recessed well:
  // card face, control edge at full strength and a soft inner shade.
  "flex field-sizing-content min-h-16 w-full rounded-md border border-border-control bg-card px-3 py-2 text-base text-foreground inset-shadow-xs md:text-sm",
  "transition-[border-color,box-shadow,background-color] duration-(--motion-fast) ease-enter motion-reduce:transition-none",
  "selection:bg-primary selection:text-primary-foreground placeholder:text-muted-foreground",
  "hover:border-muted-foreground",
  "outline-none focus-visible:border-muted-foreground focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",
  "aria-invalid:border-danger aria-invalid:ring-[3px] aria-invalid:ring-danger/20 aria-invalid:focus-visible:ring-2 aria-invalid:focus-visible:ring-danger/40",
  "disabled:cursor-not-allowed disabled:bg-muted disabled:opacity-50 disabled:inset-shadow-none",
];

/** "n characters left", never below zero. */
function charactersLeft(remaining: number) {
  const left = Math.max(0, remaining);
  return `${left} ${left === 1 ? "character" : "characters"} left`;
}

export function Textarea({
  className,
  showCount = false,
  rootClassName,
  value,
  defaultValue,
  onChange,
  maxLength,
  ...props
}: TextareaProps) {
  // Mirror the uncontrolled length so the counter can follow it; a
  // controlled `value` always wins.
  const [innerLength, setInnerLength] = React.useState(() =>
    defaultValue == null ? 0 : String(defaultValue).length,
  );
  const length = value != null ? String(value).length : innerLength;

  const limit = maxLength != null && maxLength > 0 ? maxLength : undefined;
  const remaining = limit != null ? limit - length : undefined;
  const nearAt = limit != null ? Math.max(1, Math.ceil(limit / 10)) : 0;

  // Screen readers hear the count only when it crosses a threshold on the
  // way down (entering "near", 10, 5, the limit), never on every keystroke.
  // The message stays until the next crossing so a polite announcement is not
  // cut off by the next key; it clears when the count goes back up. Derived
  // from the previous render, React's "adjust state on prop change". While the
  // counter is hidden the baseline still follows the count (and the message
  // clears), so showing it again never announces a stale crossing.
  const [prev, setPrev] = React.useState({ remaining, limit });
  const [message, setMessage] = React.useState("");
  if (!showCount && message) setMessage("");
  if (remaining !== prev.remaining || limit !== prev.limit) {
    setPrev({ remaining, limit });
    const before = prev.remaining;
    // A new limit is not a crossing (the old count was measured against the
    // old limit), and a rising count is a deletion: both clear the message.
    if (!showCount) {
      // Hidden: only move the baseline.
    } else if (remaining == null || before == null || limit !== prev.limit || remaining > before) {
      setMessage("");
    } else if ([nearAt, 10, 5, 0].some((t) => t <= nearAt && remaining <= t && before > t)) {
      setMessage(charactersLeft(remaining));
    }
  }

  // The live region only speaks at crossings, so between them its text can
  // trail the real count. The field itself is described by an accurate,
  // non-live count: a screen reader user who asks hears the true number, and
  // nothing is re-announced key by key.
  const countId = React.useId();
  const describedBy = showCount
    ? [props["aria-describedby"], countId].filter(Boolean).join(" ")
    : props["aria-describedby"];

  const textarea = (
    <textarea
      data-slot="textarea"
      value={value}
      defaultValue={defaultValue}
      maxLength={maxLength}
      onChange={(event) => {
        if (showCount) setInnerLength(event.currentTarget.value.length);
        onChange?.(event);
      }}
      className={cn(fieldClasses, showCount && "pb-7", className)}
      {...props}
      aria-describedby={describedBy}
    />
  );

  if (!showCount) return textarea;

  const state =
    remaining == null
      ? "normal"
      : remaining <= 0
        ? "limit"
        : remaining <= nearAt
          ? "near"
          : "normal";

  return (
    <div data-slot="textarea-root" className={cn("relative w-full", rootClassName)}>
      {textarea}
      <span
        data-slot="textarea-count"
        data-state={state}
        aria-hidden
        className={cn(
          "pointer-events-none absolute end-6 bottom-2 text-xs text-muted-foreground tabular-nums transition-colors duration-(--motion-fast) motion-reduce:transition-none",
          "data-[state=limit]:font-medium data-[state=limit]:text-danger-strong data-[state=near]:text-warning-strong",
        )}
      >
        {limit != null ? `${length} / ${limit}` : length}
      </span>
      <span id={countId} className="sr-only" data-slot="textarea-count-description">
        {remaining != null
          ? charactersLeft(remaining)
          : `${length} ${length === 1 ? "character" : "characters"}`}
      </span>
      <span className="sr-only" aria-live="polite" data-slot="textarea-count-status">
        {message}
      </span>
    </div>
  );
}
Pebble

Small details.
Better interfaces.

React components to explore, make your own, and build on.

Library

  • Components
  • Installation
  • Pricing

Resources

  • For agents
  • About
  • Support

Legal

  • License
  • Terms
  • Privacy
  • Final sale

Built by Pebble

A product of Praxys Solutions LLC ↗

Pebble Pro is live

$49 one time, lifetime updates ↗