# TextArea (/components/text-area)

<ReferenceLinks
  links={[
    { label: "Source", href: meta.links.source, iconName: "code" },
    { label: "Stories", href: meta.links.stories },
  ]}
/>

<Stage code={"<div style={{ width: 340 }}>\n  <TextArea\n    value=\"Tracks every research paper the lab has published, with links to authors and funding sources.\"\n    onChange={() => {}}\n  />\n</div>\n<div style={{ width: 340 }}>\n  <TextArea\n    value=\"\"\n    placeholder=\"Describe this entity type…\"\n    characterLimit={120}\n    onChange={() => {}}\n  />\n</div>\n<div style={{ width: 340 }}>\n  <TextArea\n    variant=\"subtle\"\n    value=\"Combines arXiv metadata with citation counts to rank papers by influence.\"\n    onChange={() => {}}\n  />\n</div>"}>
  <div style={{ width: 340 }}>
    <DemoState>
      <TextArea
        value="Tracks every research paper the lab has published, with links to authors and funding sources."
        onChange={noop}
      />
    </DemoState>
  </div>
  <div style={{ width: 340 }}>
    <DemoState>
      <TextArea
        value=""
        placeholder="Describe this entity type…"
        characterLimit={120}
        onChange={noop}
      />
    </DemoState>
  </div>
  <div style={{ width: 340 }}>
    <DemoState>
      <TextArea
        variant="subtle"
        value="Combines arXiv metadata with citation counts to rank papers by influence."
        onChange={noop}
      />
    </DemoState>
  </div>
</Stage>

## Installation [#installation]

1. Install the package.

```sh
npm install @hashintel/ds-components
```

2. Import the component.

```tsx
import { useState } from "react";

import { TextArea } from "@hashintel/ds-components";

export const EntityDescriptionField = () => {
  const [description, setDescription] = useState("");

  return (
    <TextArea
      value={description}
      onChange={setDescription}
      placeholder="Describe this entity type…"
      rows={4}
    />
  );
};
```

### When to use [#when-to-use]

<DoList
  items={[
    "Use TextArea for free-form text that runs longer than a few words: descriptions, notes, comments, feedback.",
    <Fragment key="0">
      Use <code>autoResize</code> for composer-style inputs — comments, chat
      messages — where the field should grow with the text.
    </Fragment>,
  ]}
/>

### When not to use [#when-not-to-use]

<DontList
  items={[
    "Don't use TextArea for single-line values such as names, emails or URLs — use TextInput.",
    "Don't ask users to type what they could pick — for a known set of options use Select, Combobox or RadioGroup.",
    "Don't use it for formatted text — TextArea is plain text only; reach for a dedicated rich-text editor.",
  ]}
/>

## Examples [#examples]

### Basic [#basic]

The default field is bordered, `md`-sized and three rows tall, and fills the width of its container.

<Stage code={"<div style={{ width: 360 }}>\n  <TextArea\n    value=\"\"\n    placeholder=\"Add a note for reviewers…\"\n    onChange={() => {}}\n  />\n</div>"}>
  <div style={{ width: 360 }}>
    <DemoState>
      <TextArea
        value=""
        placeholder="Add a note for reviewers…"
        onChange={noop}
      />
    </DemoState>
  </div>
</Stage>

### Invalid [#invalid]

Set `invalid` when the value fails validation — the border turns red and `aria-invalid` is set. Pair it with a visible error message, such as Form.Field's `errors`.

<Stage code={"<div style={{ width: 360 }}>\n  <TextArea invalid value=\"TBD\" onChange={() => {}} />\n</div>"}>
  <div style={{ width: 360 }}>
    <DemoState>
      <TextArea invalid value="TBD" onChange={noop} />
    </DemoState>
  </div>
</Stage>

### Disabled [#disabled]

Disabled fields keep their value visible but grey out and stop accepting focus. Use `disabled` only while editing is temporarily unavailable — for values the viewer can never edit, prefer `readonly`.

<Stage code={"<div style={{ width: 360 }}>\n  <TextArea\n    disabled\n    value=\"Synced from GitHub — edit the repository README to change this description.\"\n    onChange={() => {}}\n  />\n</div>"}>
  <div style={{ width: 360 }}>
    <TextArea
      disabled
      value="Synced from GitHub — edit the repository README to change this description."
      onChange={noop}
    />
  </div>
</Stage>

### Read-only [#read-only]

`readonly` drops the field styling entirely and renders the value as plain text, preserving line breaks — the same content without the affordance to edit. Unlike the native `readOnly` attribute, the result is no longer a form control: it isn't focusable and doesn't submit.

<Stage code={"<div style={{ width: 360 }}>\n  <TextArea\n    readonly\n    value=\"Tracks every research paper the lab has published, with links to authors and funding sources.\"\n    onChange={() => {}}\n  />\n</div>"}>
  <div style={{ width: 360 }}>
    <TextArea
      readonly
      value="Tracks every research paper the lab has published, with links to authors and funding sources."
      onChange={noop}
    />
  </div>
</Stage>

### Subtle variant [#subtle-variant]

`subtle` removes the border and background so the field reads as page text — for editing content in place, such as an entity description on its own page. Hovering reveals a faint border; focusing restores a solid field.

<Stage code={"<div style={{ width: 340 }}>\n  <TextArea\n    variant=\"default\"\n    value=\"The default variant always shows its border.\"\n    onChange={() => {}}\n  />\n</div>\n<div style={{ width: 340 }}>\n  <TextArea\n    variant=\"subtle\"\n    value=\"The subtle variant is borderless until hovered or focused.\"\n    onChange={() => {}}\n  />\n</div>"}>
  <div style={{ width: 340 }}>
    <DemoState>
      <TextArea
        variant="default"
        value="The default variant always shows its border."
        onChange={noop}
      />
    </DemoState>
  </div>
  <div style={{ width: 340 }}>
    <DemoState>
      <TextArea
        variant="subtle"
        value="The subtle variant is borderless until hovered or focused."
        onChange={noop}
      />
    </DemoState>
  </div>
</Stage>

### Sizes [#sizes]

`size` sets the text style and padding; `md` is the default. Match the size of neighbouring inputs, and use `sm` and below in dense chrome such as side panels and table cells.

<Stage code={"<div style={{ width: 220 }}>\n  <TextArea size=\"xxs\" rows={2} value=\"xxs\" onChange={() => {}} />\n</div>\n<div style={{ width: 220 }}>\n  <TextArea size=\"xs\" rows={2} value=\"xs\" onChange={() => {}} />\n</div>\n<div style={{ width: 220 }}>\n  <TextArea size=\"sm\" rows={2} value=\"sm\" onChange={() => {}} />\n</div>\n<div style={{ width: 220 }}>\n  <TextArea size=\"md\" rows={2} value=\"md\" onChange={() => {}} />\n</div>\n<div style={{ width: 220 }}>\n  <TextArea size=\"lg\" rows={2} value=\"lg\" onChange={() => {}} />\n</div>"}>
  <div style={{ width: 220 }}>
    <DemoState>
      <TextArea size="xxs" rows={2} value="xxs" onChange={noop} />
    </DemoState>
  </div>
  <div style={{ width: 220 }}>
    <DemoState>
      <TextArea size="xs" rows={2} value="xs" onChange={noop} />
    </DemoState>
  </div>
  <div style={{ width: 220 }}>
    <DemoState>
      <TextArea size="sm" rows={2} value="sm" onChange={noop} />
    </DemoState>
  </div>
  <div style={{ width: 220 }}>
    <DemoState>
      <TextArea size="md" rows={2} value="md" onChange={noop} />
    </DemoState>
  </div>
  <div style={{ width: 220 }}>
    <DemoState>
      <TextArea size="lg" rows={2} value="lg" onChange={noop} />
    </DemoState>
  </div>
</Stage>

### Rows [#rows]

`rows` sets the visible height in text lines (default 3) — the field doesn't grow with content unless `autoResize` is set; longer text scrolls. Match it to the expected length of the answer.

<Stage code={"<div style={{ width: 340 }}>\n  <TextArea\n    rows={2}\n    value=\"\"\n    placeholder=\"Add a short note…\"\n    onChange={() => {}}\n  />\n</div>\n<div style={{ width: 340 }}>\n  <TextArea\n    rows={6}\n    value=\"\"\n    placeholder=\"Paste the paper abstract…\"\n    onChange={() => {}}\n  />\n</div>"}>
  <div style={{ width: 340 }}>
    <DemoState>
      <TextArea
        rows={2}
        value=""
        placeholder="Add a short note…"
        onChange={noop}
      />
    </DemoState>
  </div>
  <div style={{ width: 340 }}>
    <DemoState>
      <TextArea
        rows={6}
        value=""
        placeholder="Paste the paper abstract…"
        onChange={noop}
      />
    </DemoState>
  </div>
</Stage>

### Resizing [#resizing]

`resize` sets which directions the drag handle allows: `vertical` (the default), `horizontal`, `both`, or `none`. Prefer vertical — it lets users make room without disturbing the surrounding layout; use `none` when the layout is fixed.

<Stage code={"<div style={{ width: 340 }}>\n  <TextArea\n    resize=\"vertical\"\n    value=\"Drag the handle to make room — vertically only.\"\n    onChange={() => {}}\n  />\n</div>\n<div style={{ width: 340 }}>\n  <TextArea resize=\"none\" value=\"No resize handle.\" onChange={() => {}} />\n</div>"}>
  <div style={{ width: 340 }}>
    <DemoState>
      <TextArea
        resize="vertical"
        value="Drag the handle to make room — vertically only."
        onChange={noop}
      />
    </DemoState>
  </div>
  <div style={{ width: 340 }}>
    <DemoState>
      <TextArea resize="none" value="No resize handle." onChange={noop} />
    </DemoState>
  </div>
</Stage>

### Auto-resize [#auto-resize]

`autoResize` grows and shrinks the field with its content instead of scrolling — right for composer-style inputs. `rows` becomes the minimum height, and manual resizing is disabled.

<Stage code={"<div style={{ width: 340 }}>\n  <TextArea\n    autoResize\n    rows={2}\n    value=\"Renamed the Funding Source entity type to Grant, merged the duplicate Organization entities it pointed at, and re-ran the ingestion flow to confirm nothing else links to the old type.\"\n    onChange={() => {}}\n  />\n</div>"}>
  <div style={{ width: 340 }}>
    <DemoState>
      <TextArea
        autoResize
        rows={2}
        value="Renamed the Funding Source entity type to Grant, merged the duplicate Organization entities it pointed at, and re-ran the ingestion flow to confirm nothing else links to the old type."
        onChange={noop}
      />
    </DemoState>
  </div>
</Stage>

### Character limit [#character-limit]

`characterLimit` renders a counter below the field. The limit is soft: typing past it is never blocked — the counter turns red so the writer can trim, and your validation enforces the limit on submit.

<Stage code={"<div style={{ width: 340 }}>\n  <TextArea\n    characterLimit={80}\n    includeCharCountHeight\n    value=\"Monitors the status of long-running flows.\"\n    onChange={() => {}}\n  />\n</div>\n<div style={{ width: 340 }}>\n  <TextArea\n    characterLimit={80}\n    includeCharCountHeight\n    value=\"Monitors the status of every long-running flow in the workspace and notifies the owner when one stalls.\"\n    onChange={() => {}}\n  />\n</div>"}>
  <div style={{ width: 340 }}>
    <DemoState>
      <TextArea
        characterLimit={80}
        includeCharCountHeight
        value="Monitors the status of long-running flows."
        onChange={noop}
      />
    </DemoState>
  </div>
  <div style={{ width: 340 }}>
    <DemoState>
      <TextArea
        characterLimit={80}
        includeCharCountHeight
        value="Monitors the status of every long-running flow in the workspace and notifies the owner when one stalls."
        onChange={noop}
      />
    </DemoState>
  </div>
</Stage>

### In a form field [#in-a-form-field]

Inside a Form.Field the label is associated with the textarea automatically — no `htmlForId` needed. See the Form docs for descriptions, errors and layout.

<Stage code={"<div style={{ width: 420 }}>\n  <Form.Field\n    label=\"Description\"\n    description=\"Shown on the entity type's page and in search results.\"\n  >\n    <TextArea\n      value=\"\"\n      placeholder=\"Describe this entity type…\"\n      onChange={() => {}}\n    />\n  </Form.Field>\n</div>"}>
  <div style={{ width: 420 }}>
    <FormField
      label="Description"
      description="Shown on the entity type's page and in search results."
    >
      <DemoState>
        <TextArea
          value=""
          placeholder="Describe this entity type…"
          onChange={noop}
        />
      </DemoState>
    </FormField>
  </div>
</Stage>

## Behavior [#behavior]

- Clicking anywhere inside the field's box, padding included, focuses the `<textarea>`.
- `characterLimit` never sets the native `maxLength` attribute, so typing and pasting past the limit always work — enforce the limit in validation.

## Content [#content]

- Make the placeholder a prompt for the content, sentence case, ending with an ellipsis when it invites typing: "Describe this entity type…".
- Never put the label or requirements in the placeholder — it disappears as soon as the user types. Put requirements in the Form.Field `description`.
- State character limits in the field's description and repeat them in the error: "Description must be 280 characters or fewer."

## Accessibility [#accessibility]

TextArea renders a native [`<textarea>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea), which carries the standard text-editing semantics and keyboard behavior.

### What TextArea provides [#what-textarea-provides]

- Inside a Form.Field it adopts the field's generated id, so the label is associated automatically.
- The character counter announces politely only once the limit is exceeded, instead of narrating every keystroke.

### What you must do [#what-you-must-do]

- Label every field: wrap it in a Form.Field, or set `aria-label` when a visible label is impossible — a placeholder is not a label.
- Pair `invalid` with a visible error message, such as Form.Field `errors` — the red border alone doesn't say what's wrong.
- State the character limit in the field's description — until it's exceeded, the counter is visual only.

## API reference [#api-reference]

<PropsTable
  of={TextArea}
  defaults={{
    rows: "3",
    resize: '"vertical"',
    autoResize: "false",
    variant: '"default"',
    align: '"left"',
    size: '"md"',
    includeCharCountHeight: "false",
  }}
/>
