Skip to content
On this page

TextArea

A TextArea is a multi-line text input that allows manual resizing if needed.

Guidelines

Using text areas

This form element is useful when the user needs to enter a sizable amount of free-form text, for example comments, reviews, feedback, or short essay responses.

Use TextArea to let users enter long text that exceeds one line. Avoid using TextArea if the text to be entered is short. In this case use TextInput instead.

Example of a Codex TextArea.

Specifications

Specification of TextArea.

TextArea may include the following optional elements:

  1. Start icon (optional)
    Icons can simplify the identification of specific user inputs.
  2. Placeholder (optional)
    The placeholder text provides an example of what type of information is being requested in the input.
  3. End icon (optional)
    A secondary end icon can be included if needed.
  4. Grabber (optional)
    Optionally, the grabber may be displayed to allow users the ability to vertically resize the text area as needed.

Types

According to the size properties, there are the following text area types:

With grabber

By default, a grabber will be visible, signaling to users that they can vertically resize the text area field. In this scenario, if the content cannot fit within the visible area, a scrollbar will appear to to navigate through the text that exceeds the visible area.

Use this type of text area when you require it to have a more compact size, especially in situations where it is positioned within other components like dialogs.

Example of TextArea with grabber.

Autosize

When the autosize property is enabled, the text area’s height will be automatically resized with the length of the text. There is no need for the grabber indicator in this case, and scrolling within the content is unnecessary since the entire content will be fully visible. Choose this type of text area when there is ample space available on the page where the text area is situated.

Example of TextArea with autosize.

Interaction states

Text areas have the following visually separate states:

Interaction states of TextArea: default, hover, active-focus, filled, disabled, read-only, error default, error focus, and error filled.

  1. Default
  2. Hover
  3. Active - Focus
  4. Filled
  5. Disabled
  6. Read-only
  7. Error default
  8. Error focus
  9. Error filled

Demos

Configurable

NameValue
Props
status
autosize
startIcon
endIcon
placeholder
disabled
readonly
rows
View
Reading direction
Note: For icon properties, the relevant icon also needs to be imported from the @wikimedia/codex-icons package. See the usage documentation for more information.

Default

The TextArea component uses v-model to two-way bind the reactive reference to the value of <textarea>. The reactive reference will automatically update when the value changes in the <textarea>. The value updates due to an emitted input event.

By default, the initial value of the autosize prop is false. When autosize is false, the textarea will display a grabber/resize tool and a scrollbar to view the overflow content. The <textarea> can be manually resized vertically to increase height of the element.

Note: The initial min-height of the <textarea> is set to 64px.

Browser Support Warning

While our design system strives to provide a consistent experience across different platforms and browsers, it's important to be aware that the vertical resizing feature will not be available on iOS devices, including iPhones and iPads. This limitation is due to the default behavior of iOS Safari.

With placeholder

We passed in a native attribute, placeholder, to hint to users what to enter into the control.

Note: Placeholders are not a substitute for a proper <label> element tied to the control.

With rows

This example demonstrates how to pass in the native attribute, rows, to the <textarea>.

The rows attribute takes a positive number which represents the number of text lines to display in the control.

With autosize

When the autosize prop is set to true, the TextArea automatically grows with the height of the content inside <textarea>.

The grabber/resize tool is not displayed when autosize is set to true.

With icons

TextArea can pass in a start icon and end icon as props. This example shows how to add icons to the component. Also see Icon.

With disabled

You can disable the component by adding the disabled attribute.

When <textarea> is disabled, the user cannot interact with the control. Users cannot click or select in the control and the form cannot be submitted.

With readonly

You can make the component readonly by adding the readonly attribute.

When <textarea> is readonly, the user cannot modify the value of the control. Some key differences between disabled and readonly is that readonly does not prevent users from selecting and clicking in the form. Users can highlight and copy content in readonly. Readonly is tabbable and the form can be submitted.

One example usage of readonly textarea is when you want to prevent a user from typing into the textarea until a condition is met like selecting a a checkbox. In this situation, when the condition is met we can use JavaScript to remove the readonly to make the textarea editable.

Form field

A TextArea can be wrapped in the Field component to add features like a semantic label, description and help text, validation messages, and more. See the Field page for more information.

Vue usage

v-model is used to track the current value of the textarea. See the events docs for details on emitted events and their properties.

Attributes passed to textarea

This component will pass any HTML attributes applied to it, except for CSS class, to the <textarea> element within the component.

Props

Prop nameDescriptionTypeValuesDefault
modelValueCurrent value of the textarea.

Provided by v-model binding in the parent component.
string-''
statusstatus attribute of the textarea.ValidationStatusType'default', 'error''default'
disabledWhether the textarea is disabled.boolean-false
autosizeDescribes whether the textarea grows vertically to show all text.

When autosize is true, the textarea automatically grows in height (vertically). The height of the textarea expands while the user types in the textarea. The content inside the textarea is visible and there's no scroll.
booleantrue, falsefalse
startIconAn icon at the start of the textarea element. Similar to a ::before pseudo-element.Icon|undefined-undefined
endIconAn icon at the end of the textarea element. Similar to an ::after pseudo-element.Icon|undefined-undefined

Events

Event namePropertiesDescription
update:modelValuemodelValue string - The new model valueWhen the textarea value changes.