# Text area API

> Explore the API of Cimpress UI's text area component.

Source: https://ui.cimpress.io/components/text-area/api/

## Import

```tsx
import { TextArea } from '@cimpress-ui/react';
```

## Controlled/uncontrolled usage

```tsx
import { TextArea, Stack } from '@cimpress-ui/react';
import { useState } from 'react';

export default function Demo() {
  const [feedback, setFeedback] = useState('Everything is fine.');

  return (
    <Stack gap={32}>
      <TextArea label="Feedback (controlled)" rows={3} value={feedback} onChange={setFeedback} />
      <TextArea label="Feedback (uncontrolled)" rows={3} defaultValue="Everything is fine." />
    </Stack>
  );
}
```

## Imperative API

```tsx
import { Button, Stack, TextArea, type TextAreaApi } from '@cimpress-ui/react';
import { useRef } from 'react';

export default function Demo() {
  const apiRef = useRef<TextAreaApi>(null);

  return (
    <Stack gap={16}>
      <TextArea label="Feedback" rows={3} defaultValue="Everything is fine." apiRef={apiRef} />

      <Stack gap={16} direction={{ md: 'horizontal' }}>
        <Button onPress={() => apiRef.current?.focus()}>Focus</Button>
        <Button onPress={() => apiRef.current?.select()}>Select contents</Button>
      </Stack>
    </Stack>
  );
}
```

## Accessibility notes

`TextArea` requires a textual label to remain accessible to assistive technologies. See our [accessibility guide](/dev-guides/accessibility#labelling) for more details.

## Forms

Text area can integrate with native HTML forms. See our [forms guide](/dev-guides/forms) to learn how to work with forms.

## API reference

### TextArea

Allows users to enter multiple lines of text with a keyboard.

See [text area usage guidelines](https://ui.cimpress.io/components/text-area/).

- `ref`: `Ref<HTMLDivElement>`

  The `ref` type for this component.

**Props: `TextAreaProps`**

- `autoCapitalize`: `'off' | 'none' | 'on' | 'sentences' | 'words' | 'characters' | (string & ({  }))`

  Controls whether inputted text is automatically capitalized. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/autocapitalize).

- `autoCorrect`: `'off' | 'on'`

  Controls whether inputted text can be autocorrected by the browser. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/autocorrect).

- `rows`: `number`

  Controls how many lines of text are visible by default. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/HTMLTextAreaElement/rows).

- `spellCheck`: `boolean`

  Controls whether the inputted text may be checked for spelling errors. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/spellcheck).

- `wrap`: `'soft' | 'hard'`

  Controls how the inputted text will be wrapped for form submission. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/HTMLTextAreaElement/wrap).

  Defaults to `'soft'`.

- `id`: `string`

  The element's unique identifier. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id).

- `data-cim-style-root`: `boolean`

  Use this attribute to "claim" the component tree for exclusive Cimpress UI usage.

- `UNSAFE_className`: `string`

  Sets the CSS className for the element. Only use as a **last resort**. Use style props instead.

  See [styling guide](https://ui.cimpress.io/dev-guides/styling/).

- `UNSAFE_style`: `CSSProperties`

  Sets the CSS style for the element. Only use as a **last resort**. Use style props instead.

  See [styling guide](https://ui.cimpress.io/dev-guides/styling/).

- `label`: `string`

  The content to display as the label.

- `aria-label`: `string`

  Defines a string value that labels the current element.

- `aria-labelledby`: `string`

  Identifies the element (or elements) that labels the current element.

- `aria-describedby`: `string`

  Identifies the element (or elements) that describes the object.

- `aria-details`: `string`

  Identifies the element (or elements) that provide a detailed, extended description for the object.

- `form`: `string`

  The `<form>` element to associate the input with.
  The value of this attribute must be the id of a `<form>` in the same document.
  See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input#form).

- `name`: `string`

  The name of the input element, used when submitting an HTML form. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input#name).

- `description`: `string`

  A description for the field. Provides a hint such as specific requirements for what to choose.

- `error`: `FieldError`

  An error message for the field.

- `validate`: `(value: string) => string | true | string[] | undefined`

  A function that returns an error message (or `true`) if a given value is invalid.
  Validation errors are displayed to the user when the form is submitted.
  For real-time validation, use the `error` prop instead.

- `placeholder`: `string`

  The placeholder text displayed in the input field.

- `apiRef`: `RefObject<TextAreaApi | null>`

  A React ref that allows access to the imperative API of this component.

- `autoComplete`: `string`

  Describes the type of autocomplete functionality the input should provide if any. See
  [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefautocomplete).

- `maxLength`: `number`

  The maximum number of characters supported by the input. See
  [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefmaxlength).

- `minLength`: `number`

  The minimum number of characters required by the input. See
  [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefminlength).

- `type`: `'search' | (string & ({  })) | 'text' | 'tel' | 'url' | 'email' | 'password'`

  The type of input to render. See
  [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdeftype).

  Defaults to `'text'`.

- `inputMode`: `'search' | 'none' | 'text' | 'tel' | 'url' | 'email' | 'numeric' | 'decimal'`

  Hints at the type of data that might be entered by the user while editing the element or its
  contents. See
  [MDN](https://html.spec.whatwg.org/multipage/interaction.html#input-modalities:-the-inputmode-attribute).

- `onKeyDown`: `(e: KeyboardEvent) => void`

  Handler that is called when a key is pressed.

- `onFocus`: `(e: FocusEvent<HTMLInputElement>) => void`

  Handler that is called when the element receives focus.

- `onBlur`: `(e: FocusEvent<HTMLInputElement>) => void`

  Handler that is called when the element loses focus.

- `autoFocus`: `boolean`

  Whether the element should receive focus on render.

- `isRequired`: `boolean`

  Whether user input is required on the input before form submission.

- `isDisabled`: `boolean`

  Whether the input is disabled.

- `isReadOnly`: `boolean`

  Whether the input can be selected but not changed by the user.

- `value`: `string`

  The current value (controlled).

- `defaultValue`: `string`

  The default value (uncontrolled).

- `onChange`: `(value: string) => void`

  Handler that is called when the value changes.

- `isInvalid`: `boolean`

  Whether the value is invalid.

**Props: `StyleProps`**

- `margin`: `Responsive<Spacing | "auto">`

  The amount of margin applied to all edges of this component.

- `marginX`: `Responsive<Spacing | "auto">`

  The amount of margin applied to the left and right edges of this component. Takes priority over `margin`.

- `marginY`: `Responsive<Spacing | "auto">`

  The amount of margin applied to the top and bottom edges of this component. Takes priority over `margin`.

- `marginTop`: `Responsive<Spacing | "auto">`

  The amount of margin applied to the top edge of this component. Takes priority over `marginY` and `margin`.

- `marginRight`: `Responsive<Spacing | "auto">`

  The amount of margin applied to the right edge of this component. Takes priority over `marginX` and `margin`.

- `marginBottom`: `Responsive<Spacing | "auto">`

  The amount of margin applied to the bottom edge of this component. Takes priority over `marginY` and `margin`.

- `marginLeft`: `Responsive<Spacing | "auto">`

  The amount of margin applied to the left edge of this component. Takes priority over `marginX` and `margin`.
