Skip to main content

Text Area

Text Area is a form control that lets people enter several lines of text, such as a project description or feedback.

Import

import { TextArea } from '@vortexlabs/vortex-native';
import type { TextAreaProps } from '@vortexlabs/vortex-native';

Other links

import { TextArea } from "@vortexlabs/vortex-native";

<TextArea.Root
  size="md"
  variant="outline"
  disabled={false}
  error={false}
  gap={2}
>
  <TextArea.Label>Project description</TextArea.Label>
<TextArea.Input name="description" rows={3} placeholder="Describe the project" />
<TextArea.ErrorMessage>Enter a project description.</TextArea.ErrorMessage>
</TextArea.Root>

Features

  • Composes a multiline input with a label and messages.
  • Supports controlled and uncontrolled text.
  • Grows from a configurable number of rows.

Anatomy

<TextArea.Root>
  <TextArea.Label>Project description</TextArea.Label>
  <TextArea.Input name="description" />
  <TextArea.HelperText>Summarize the goal in a few sentences.</TextArea.HelperText>
  <TextArea.ErrorMessage>Enter a valid value.</TextArea.ErrorMessage>
</TextArea.Root>
Component Part
Description
Shares size, appearance, and state with the input and its supporting text.
Names the textarea.
Edits multiple lines of text and identifies changes by name.
Adds supporting text below the textarea.
Explains the error while error is set.

Variants and Sizes

Use variant="fill" for a filled surface. Set size on the root to size the input and its spacing.

<Stack gap={4}>
  <TextArea.Root variant="outline" size="sm">
    <TextArea.Label>Short bio</TextArea.Label>
    <TextArea.Input name="bio" />
  </TextArea.Root>
  <TextArea.Root variant="fill" size={{ xs: "sm", md: "md" }}>
    <TextArea.Label>About your work</TextArea.Label>
    <TextArea.Input name="work" />
  </TextArea.Root>
</Stack>

Initial Height

Set rows for a longer starting field. The input grows to six rows, or its starting height if taller, then scrolls.

<TextArea.Root>
  <TextArea.Label>Delivery instructions</TextArea.Label>
  <TextArea.Input name="instructions" rows={4} />
  <TextArea.HelperText>Include an entrance or access code.</TextArea.HelperText>
</TextArea.Root>

Controlled Text and Character Limit

Pass value to the input and update it in onChange. Set attributes.maxLength to enforce a character limit.

import { TextArea } from "@vortexlabs/vortex-native";
import { useState } from "react";

export const ShortBio = () => {
  const [bio, setBio] = useState("");

  return (
    <TextArea.Root>
      <TextArea.Label>Short bio</TextArea.Label>
      <TextArea.Input
        name="bio"
        value={bio}
        onChange={({ value }) => setBio(value)}
        attributes={{ maxLength: 160 }}
      />
      <TextArea.HelperText>{bio.length} / 160 characters</TextArea.HelperText>
    </TextArea.Root>
  );
};

Validation

Set error on the root to show the error message. Keep instructions that always apply in TextArea.HelperText.

import { TextArea } from "@vortexlabs/vortex-native";
import { useState } from "react";

export const Feedback = () => {
  const [message, setMessage] = useState("");
  const [touched, setTouched] = useState(false);

  return (
    <TextArea.Root error={touched && message.trim().length === 0}>
      <TextArea.Label>Feedback</TextArea.Label>
      <TextArea.Input
        name="feedback"
        value={message}
        onChange={({ value }) => setMessage(value)}
        onBlur={() => setTouched(true)}
      />
      <TextArea.HelperText>Describe what you were trying to do.</TextArea.HelperText>
      <TextArea.ErrorMessage>Enter feedback before sending.</TextArea.ErrorMessage>
    </TextArea.Root>
  );
};

Disabled and Read Only

Set disabled on the root to mark the field unavailable. Set attributes.readOnly on the input to keep its value visible without editing.

<Stack gap={4}>
  <TextArea.Root disabled>
    <TextArea.Label>Reviewer notes</TextArea.Label>
    <TextArea.Input name="reviewer" placeholder="Review has not started" />
  </TextArea.Root>
  <TextArea.Root>
    <TextArea.Label>Original request</TextArea.Label>
    <TextArea.Input name="request" defaultValue="Please add an offline mode." attributes={{ readOnly: true }} />
  </TextArea.Root>
</Stack>

Accessibility

Description
Plain label text names the native input. When a custom component supplies the label, pass its text through the input’s attributes["aria-label"].
While the root has an error, the error message contributes to the input’s accessibility hint.