Beta Preview

TextArea

TextAreas are multiline text inputs, useful for cases where users have a sizable amount of text to enter. They allow for all customizations that are available to text fields.

 
size 
labelPosition 
 
contextualHelp 
isDisabled 
import {TextArea} from '@react-spectrum/s2';

<TextArea label="Description" />

Value

Use the value or defaultValue prop to set the text value, and onChange to handle user input.

Your comment:

import {TextArea} from '@react-spectrum/s2';
import {useState} from 'react';

function Example() {
  let [name, setName] = useState('');
  
  return (
    <>
      <TextArea
        label="Comment"
        value={name}
        onChange={setName} />
      <p>Your comment: {name}</p>
    </>
  );
}

Forms

Use the name prop to submit the text value to the server. Set the isRequired, minLength, or maxLength props to validate the value, or implement custom client or server-side validation. See the Forms guide to learn more.

Please provide at least 10 characters.
isRequired 
necessityIndicator 
 
 
import {TextArea, Button, Form} from '@react-spectrum/s2';

function Example(props) {
  return (
    <Form>
      <TextArea
        {...props}
        label="Comment"
        name="email"
        description="Please provide at least 10 characters."
        isRequired
        minLength={10}
      />
      <Button type="submit">Submit</Button>
    </Form>
  );
}

API

NameTypeDefault
size'S''M''L''XL'Default: 'M'
The size of the text field.
enterKeyHint'enter''done''go''next''previous''search''send'Default:
An enumerated attribute that defines what action label or icon to preset for the enter key on virtual keyboards. See MDN.
isDisabledbooleanDefault:
Whether the input is disabled.
isReadOnlybooleanDefault:
Whether the input can be selected but not changed by the user.
inputMode'none''text''tel''url''email''numeric''decimal''search'Default:
Hints at the type of data that might be entered by the user while editing the element or its contents. See MDN.
autoCorrectstringDefault:
An attribute that takes as its value a space-separated string that describes what, if any, type of autocomplete functionality the input should provide. See MDN.
spellCheckstringDefault:
An enumerated attribute that defines whether the element may be checked for spelling errors. See MDN.
stylesDefault:
Spectrum-defined styles, returned by the style() macro.
valuestringDefault:
The current value (controlled).
defaultValuestringDefault:
The default value (uncontrolled).
onChange(value: T) => voidDefault:
Handler that is called when the value changes.