Skip to content

Text area - Frameworks

A text area allows users to input extended text content that covers multiple lines.

iOSreleasedReactreleasedVuereleased

React

Import

You can import the component like so:

js
import { TextArea } from '@warp-ds/react';

or import it individually to optimize your JS bundle size by adding only the components you need:

js
import { TextArea } from '@warp-ds/react/components/textarea';

Syntax

jsx
<TextArea label="Description" />

Props

Optional Props

NameTypeDefaultDescription
autoFocusbooleanWhether the element should receive focus on render.
classNamestringAdditional classes to include.
styleCSSPropertiesAdditional CSS styles for the container.
defaultValuestring & (string|number|readonly string[])The default value (uncontrolled).
disabledbooleanWhether the input is disabled.
errorbooleanRenders the field in an invalid state. Often paired together with helpText to provide feedback about the error. @deprecated use invalid instead.
invalidbooleanRenders the field in an invalid state. Often paired together with helpText to provide feedback about the error.
helpTextReactNodeThe content to display as the help text.
idstringThe element's unique identifier. See MDN.
labelReactNodeThe content to display as the label.
maxstring|numberStandard input max attribute, to be used with type="number". See MDN.
minstring|numberStandard input min attribute, to be used with type="number". See MDN.
maxLengthnumberThe maximum number of characters supported by the input. See MDN.
minLengthnumberThe minimum number of characters supported by the input. See MDN.
namestringThe name of the input element, used when submitting an HTML form. See MDN.
patternstringRegex pattern that the value of the input must match to be valid. See MDN.
placeholderstringText hint that occupies the text input when it is empty.
readOnlybooleanWhether the input can be selected but not changed by the user.
requiredbooleanWhether user input is required on the input before form submission.
childrenReactNodeFor affix use.
valuestringThe current value (controlled).
optionalbooleanIndicates that the textarea is not required.

Value

A TextArea's value is empty by default, but an initial, uncontrolled, value can be provided using the defaultValue prop. Alternatively, a controlled value can be provided using the value prop.

js
function Example() {
  let [value, setValue] = React.useState('Lorem ipsum');

  return (
    <div className="flex space-x-32">
      <TextArea label="Description (Uncontrolled)" defaultValue="Lorem ipsum" />

      <TextArea
        label="Description (Controlled)"
        onChange={(event) => setValue(event.target.value)}
        value={value}
      />
    </div>
  );
}

Labeling

A visual label should be provided for the TextArea using the label prop.

Optional

Add the optional prop to indicate that the textarea is not required.

jsx
<TextArea label="Description" optional />

Help text

TextAreas can provide additional context with helpText if the label and placeholder aren't enough.

jsx
<TextArea label="Description" helpText="Maximum 200 characters" />

Validation

TextAreas can communicate to the user whether the current value is invalid. Implement your own validation logic in your app and set the invalid prop to display it as invalid.

invalid is often paired with helpText to provide feedback to the user about the error.

jsx
<TextArea label="Description" invalid helpText="Maximum 200 characters" />

Visual options

Placeholder

jsx
<TextArea label="Description" placeholder="Lorem ipsum dolor sit amet" />

Placeholder text can be used to describe the expected value or formatting for the TextArea. Placeholder text will only appear when the TextArea is empty, and should not be used as a substitute for labeling the component with a visible label.

Disabled

Keep in mind that using disabled in its current form is an anti-pattern. There will always be users who don't understand why an element is disabled, or users who can't even see that it is disabled because of poor lighting conditions or other reasons. Please consider more informative alternatives before choosing to use disabled on an element.

jsx
<div className="flex flex-col y-space-32">
  <TextArea label="Description" disabled value="Lorem ipsum dolor sit amet" />
  <TextArea label="Description" disabled />
</div>

Read only

The readOnly boolean prop makes the TextArea's text content immutable. Unlike disabled the TextArea remains focusable and the contents can still be copied. See the MDN docs for more information.

jsx
<div className="flex flex-col y-space-32">
  <TextArea
    label="Description"
    readOnly
    defaultValue="Lorem ipsum dolor sit amet"
  />
  <TextArea label="Description" readOnly />
</div>

Height (text rows)

The minimumRows prop sets the minimum number of text rows the TextArea should show.

jsx
<TextArea label="Description" minimumRows={3} />

The maximumRows prop sets the maximum number of text rows the TextArea should show.

jsx
<TextArea
  label="Description"
  maximumRows={3}
  defaultValue={'Lorem\nipsum\ndolor\nsit\namet'}
/>

Questions?

Feel free to ask any questions on usage in the Warp DS Slack channel: #warp-design-system