TextArea

A multiline native editor with a character counter.

  • Native host
  • In the first release
import { TextArea, textAreaPrimitive } from "nitro-ui-sdk/text-area";
HeroUI Native
TextArea
Expo UI
TextField (multiline)
  • TextArea example screen, light appearance
    Light
  • TextArea example screen, dark appearance
    Dark
On this page

TextArea is a native multiline editor for longer values and notes. It can keep a fixed height or grow by rows, with an optional character counter.

Anatomy

import { TextArea } from "nitro-ui-sdk/text-area";

<TextArea.Root label="Notes" maxLength={280}>
  <TextArea.Label />
  <TextArea.Editor />
  <TextArea.Hint />
  <TextArea.Counter />
  <TextArea.Error />
</TextArea.Root>;
Part Description
Root Owns the value and row configuration.
Label Visible field name.
Editor Native multiline editor.
Hint Helper text.
Counter Current number of UTF-16 code units.
Error Validation message.

Usage

import { TextArea } from "nitro-ui-sdk/text-area";

<TextArea.Root label="Notes" resize="growing" minRows={2} maxRows={6} />;

Variants and sizes

Choose outline or filled for the surface and sm, md or lg for the field scale. Rows determine the multiline height, with a 44 pt minimum touch target. Set resize="growing" to fit typed content up to maxRows.

States

The focused editor uses the focus border. Invalid fields use the danger border. Disabled fields reduce opacity and reject editing actions. Reaching maxLength triggers one character-count announcement.

Controlled

Pass defaultValue for a local value or value with onValueChange to own it. The editor reconciles to the owner’s value after each edit, including a declined request.

import { useState } from "react";
import { TextArea } from "nitro-ui-sdk/text-area";

export function Example() {
  const [value, setValue] = useState("");
  return <TextArea.Root label="Notes" value={value} onValueChange={setValue} />;
}

Props

TextArea.Root

Prop Type Default Description
label string Required Localized name spoken by assistive technology.
hint string — Additional instructions spoken with the field.
error string — Validation message spoken with the field.
invalid boolean false Applies the invalid appearance. A nonempty error also marks it invalid.
disabled boolean false Disables editing and reduces opacity.
variant TextAreaVariant "outline" Field surface appearance.
size TextAreaSize "md" Visible field size.
value string — Owner-controlled text.
defaultValue string "" Initial text in uncontrolled mode.
onValueChange (value: string, details: ActionDetails) => void — Receives the requested text. Call details.preventDefault() to decline.
onValueCommit (value: string, details: ActionDetails) => void — Runs once per accepted edit that changes the value.
placeholder string — Native placeholder.
resize TextAreaResize "fixed" Fixed row count or content-driven growing height.
minRows number 3 Minimum number of rows.
maxRows number 8 Growing height limit. Zero removes the row limit.
maxLength number — Maximum UTF-16 code units.
autocapitalize TextCapitalization "sentences" Native capitalization mode.
autocorrect boolean true Use OS autocorrection.
counterLabel (count: number, maxLength: number | undefined) => string — Localized spoken count.
styles PartStyles<TextAreaPart, TextAreaVariant, TextAreaSize, TextAreaState> — Style resolvers keyed by part.
api Controller<TextAreaActions> — Attach a controller created with the primitive.
agentId string — Identity for replacing a field in a reused view.
children ReactNode — Compound anatomy override.

TextArea.Label, TextArea.Hint and TextArea.Error

Prop Type Default Description
part TextAreaPart — Override the style key for this part.
children string Root text Visible text for this part.

TextArea.Counter

Prop Type Default Description
part TextAreaPart — Override the style key for this part.
children string count or count/maxLength Visible count. Includes the limit when maxLength is set.

TextArea.Editor

Prop Type Default Description
part TextAreaPart — Override the style key for this part.

Controller API

import { TextArea, textAreaPrimitive } from "nitro-ui-sdk/text-area";

const api = textAreaPrimitive.createApi();
const field = <TextArea.Root label="Notes" api={api} />;

// Use api.current after the field mounts.
export { field, api };
Action Signature Result
focus (source?: ActionSource) => ActionStatus Focuses the editor when it is available.
blur (source?: ActionSource) => ActionStatus Dismisses native editing.
setValue (value: string, source?: ActionSource) => ChangeStatus Requests a new value.
clear (source?: ActionSource) => ChangeStatus Requests an empty value.

Controlled edits return requested while the owner renders. Agent calls resolve after that commit.

Styles

import { TextArea } from "nitro-ui-sdk/text-area";

<TextArea.Root label="Notes" styles={{ counter: ({ tokens, state }) => ({ text: { color: state.full ? tokens.colors.danger : tokens.colors.muted } }) }} />;

Resolvers receive tokens, variant, size, and state. State includes disabled, invalid, focused, and empty. full indicates that the value has reached the limit.

Accessibility

The native editor speaks label as its name and reads error before hint. Editing, selection and dictation are platform-owned. The editor includes the localized count in its hint when configured. Return inserts a line break.

Agent API

Action Arguments Notes
focus None Focus the editor.
setValue String Request a value. Controlled owners can decline.
clear None Request an empty value.

Platform notes

iOS Android
Implementation UIKit text view with native content measurement and scrolling. Multiline EditText with native content measurement and scrolling.
Verification Native iOS harness in the example app. Kotlin is written for Android. The Android NDK is unavailable on this machine, so no Android build was run.