<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-5HGSQD2L" height="0" width="0" style="display:none;visibility:hidden" title="GTM"></iframe>

Text Area

Input field for entering more than one line of text.

A TextArea is an input field that allows the user to enter more than one line of text.

Usage

The preview has been updated.

Our Textarea component uses the native HTML <textarea> input, so it can use the various properties of the native element, including the rows property to control the textarea's default height.

Resizing

By default, users can resize the Textarea both vertically and horizontally. If you want to limit resizing to the vertical axis, you can add the "resize vertical" option:

The preview has been updated.


This pairs well with the "full width" option, which makes the component take up all available width:

The preview has been updated.

Labels, Errors, and Helper Text

Use skin="error" for when the current value is invalid:

The preview has been updated.

In React, when you use a TextArea inside a FormField along with other components, the "error" skin will be automatically applied when a FormError component is present. You'll get some other convenience behaviors, including the textarea's label automatically having its for attribute associated with the input. Refer to Form for more.

In vanilla, you can get the error skin by applying the class swan-textarea-skin-error to the input.

Managing State

As is the case with most form elements, folks often want to "control" this component. Controlling a component means that you take ownership over its state rather than letting the browser manage the state for you. When you control component, you own the source of truth for the UI. This means that you don't need to query the DOM in order to determine the current value of the element. So, when it comes time to use the value of the element somewhere else (e.g. submitting the value to a back-end service) you can trust your stored state.

If you'd like to control a TextArea, you'll need store the current value somewhere (e.g. React state or a Redux store), and you'll need to provide a handler to update that value when the user interacts with the component.

e.g.

The preview has been updated.

If you don't care about the state of the TextArea, you can simply omit the value and onChange props. In this case, you may add the defaultValue prop in order to specify the initial value of the TextArea without committing to fully managing the state.

We don't have any guidelines for Text Area yet but reach out to us with the questions you'd like answered or if you'd like to contribute any guidelines.

Props

TextArea
This component is implemented using the <textarea /> as the root element. You can utilize the native attributes supported by <textarea /> tag. The ref is directly assigned to the root element, allowing you to access and manipulate it as needed.
See core props for additional props that can be applied to this component.
proptyperequireddescriptiondefault
skin"standard" | "error" | nullfalse
The visual variant. Note that error is implied if the TextInput is used inside of a FormInput that also contains a FormError. Available options: 'standard', 'error'
null
resize"both" | "vertical" | nullfalse
Which dimensions of the TextArea should be resizable. Available options: 'vertical', 'both'
null
fullWidthboolean | nullfalse
Whether or not the TextArea should expand to fill the full width of its container
null

Related