TextArea

A text area serves as a multi-line, plain-text editing interface.

Usage

Disabled

A text area in a disabled state shows that an input field exists, but is not available in that circumstance. This can be used to maintain layout continuity and communicate that a field may become available later.

ReadOnly

The isReadOnly prop makes the text area's text content immutable. Unlike isDisabled, the text area remains focusable and the contents can still be copied. See the MDN docs for more information.

Error

A text area can be displayed in an error state to indicate that the user input is invalid.

Sizes

A text area can vary in size. The height is determined by the number of rows. Each size has a unique font size, resulting in varying heights across different sizes.

Labeling

If a visible label isn't specified, an aria-label must be provided to the text area for accessibility. If the field is labeled by a separate element, an aria-labelledby prop must be provided using the ID of the labeling element instead.

Description

A text area can have a description using the HelperMessage component to provide additional context to the user.

Character Count

A character count can be displayed below the input. The character count is based on the maxLength prop. If the maxLength prop is not set, the character count will not be displayed.

Max Length Exceeded

To exceed the max length, set the allowExceedingMaxLength prop to true – default is false. When the character count is displayed, it turns red if the max length is exceeded.

Note: If allowExceedingMaxLength is set, a character count is required to be set as well.

Rows

The rows prop can be used to set the height of the text area and should be used in favor of the height prop. One row is equivalent to the height of one line of text.

Max Rows

The maxRows prop can be used to set the maximum height of the text area and should be used in favor of the maxHeight prop. It differs from the rows prop in that it will not set the initial height of the text area.

Vertical Resize

The resizeMode prop can be used to set the resize behavior of the text area. The default behavior is none, which prevents the user from resizing the text area. The vertical behavior allows the user to resize the text area vertically.

Props

showCharacterCount?

True to display the number of remaining allowed characters on the right of the input. Requires a valid value in the "maxLength" prop.

maxRows?

The maximum number of visible text lines before displaying a scrollbar.

placeholder?

The placeholder text when the TextArea is empty.

rows?

See MDN.

cols?

See MDN.

isFluid?

If true, the TextArea will take all available width.

allowExceedingMaxLength?

This should only be used with the showCharacterCount prop. If true, the TextArea will allow the text to go over the max length, but it will add an error look to the character count.

resizeMode?

The resize mode value of the TextArea. It's equivalent to the CSS resize property.

Defaults to none.
inputRef?

A ref for the HTML textarea element.

inputGroupProps?

The props for the InputGroup.

remainingCharacterCountProps?

The props for the RemainingCharacterCount.

style?

The inline style for the element. A function may be provided to compute the style based on component state.

pattern?

Regex pattern that the value of the input must match to be valid. See MDN.

validationBehavior?

Whether to use native HTML form validation to prevent form submission when the value is missing or invalid, or mark the field as required or invalid via ARIA.

Defaults to 'native'.
isDisabled?

Whether the input is disabled.

isReadOnly?

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

isRequired?

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

isInvalid?

Whether the value is invalid.

validate?

A function that returns an error message if a given value is invalid. Validation errors are displayed to the user when the form is submitted if validationBehavior="native". For realtime validation, use the isInvalid prop instead.

autoFocus?

Whether the element should receive focus on render.

value?

The current value (controlled).

defaultValue?

The default value (uncontrolled).

onChange?

Handler that is called when the value changes.

id?

The element's unique identifier. See MDN.

autoComplete?

Describes the type of autocomplete functionality the input should provide if any. See MDN.

maxLength?

The maximum number of characters supported by the input. See MDN.

minLength?

The minimum number of characters required by the input. See MDN.

type?

The type of input to render. See MDN.

inputMode?

Hints at the type of data that might be entered by the user while editing the element or its contents. See MDN.

name?

The name of the input element, used when submitting an HTML form. See MDN.

className?

The CSS className for the element. A function may be provided to compute the class based on component state.

description?

The helper message of the field.

errorMessage?

The error message of the field.

label?

The label of the field.

necessityIndicator?

Whether the required state should be shown as an asterisk or a label, which would display (Optional) on all non required field labels.

size?

A CheckboxGroup can vary in size.

Defaults to md.

Migration Notes

Coming from Orbiter, you should be aware of the following changes:

  • Boolean props are now prefixed by is.
  • There is no longer a loading state.
  • icon prop has been removed since it is not used in a TextArea.
  • button prop has been removed.
  • wrapperProps no longer exists.
  • validationState has been changed to isInvalid.
  • showCharacterCount has been added.