Text area

Import
import { TextArea } from "reshaped";
import type { TextAreaProps } from "reshaped";
Related components
Full keyboard navigation support
Can be controlled and uncontrolled
Automatic integration with FormControl utility


Usage

Form fields have a required name property, so that's the only property you have to pass to TextArea to start using it. If you need to handle its change events - add an onChange property to it.

<TextArea
name="email"
placeholder="Enter your email"
onChange={(args) => console.log(args)}
/>

Controlled/Uncontrolled

Same as when using native inputs in React, TextArea can be used as a controlled or uncontrolled component. By default, TextArea is uncontrolled and lets you define its default value using the defaultValue property. In this case, all change events are handled automatically. This approach is helpful when you're pre-filling a form from a data source, but you don't need to control the further behavior of the input.

<TextArea
name="email"
placeholder="your.email@gmail.com"
defaultValue="reshaped.example@gmail.com"
/>

If you need to control the state of the field manually, you can use the value property. That will give you complete control of the component value and will stop handling the value automatically. You will have to update the state using the onChange handler and will be able to add custom logic before that happens.

<TextArea
name="email"
placeholder="your.email@gmail.com"
value="reshaped.example@gmail.com"
onChange={({ value }) => {
/* Update your state here */
}}
/>

Sizes

TextArea comes in 3 sizes, with the medium size used by default. All sizes are aligned with the paddings of other input components like TextField or Select.

<View gap={3}>
<TextArea name="desc" size="medium" placeholder="Enter the description" />
<TextArea name="desc" size="large" placeholder="Enter the description" />
<TextArea name="desc" size="xlarge" placeholder="Enter the description" />
</View>

TextField supports responsive syntax for its size property, which means you can change its size based on the viewport.

<TextArea
name="desc"
size={{ s: "medium", l: "xlarge" }}
placeholder="Enter the description"
/>

States

You can use hasError property to show the user that TextArea is not passing the form validation.

<TextArea name="desc" hasError />

You can disable TextArea with the disabled flag. However, remember that disabling the field will remove it from the form submit query.

<TextArea name="desc" disabled />

Using with FormControl

To let the user know what data you expect them to type in, add labels or status messages to your fields with the help of the FormControl utility. In case you're using xlarge TextArea size, you can also combine it with the large FormControl size for better visual alignment.

Note: Don't use placeholders as labels for the fields as users won't see the placeholder when input contains a value.

<FormControl>
<FormControl.Label>Email</FormControl.Label>
<TextArea name="name" placeholder="example@gmail.com" />
</FormControl>

Accessibility

  • When using TextArea without a label - make sure to provide a text description. You can either provide the label by using the FormControl utility or by passing inputAttributes={{ 'aria-label': 'Your label' }} to the component if you don't want to display it visually.
<TextArea attributes={{ "aria-label": "Description" }} />
Previous