Textareas collect data from the user and allow multiple lines of text.
Textareas collect data from the user and allow multiple lines of text.
Use the label attribute to give the textarea an accessible label. For labels that contain HTML, use the label slot instead.
Add descriptive help text to a textarea with the help-text attribute. For help texts that contain HTML, use the help-text slot instead.
Use the placeholder attribute to add a placeholder.
Use the maxlength and show-count-text attributes together to show a text counter while the user types into the input.
Use the required attribute to specify the textarea is a required field when using within a form.
Use the disabled attribute to disable a textarea.
Use the readonly attribute to make a textarea read-only.
Use the error-text attribute to customize the error message shown. Read more about error validation here .
Use the rows attribute to change the number of text rows that get shown.
By default, textareas can be resized vertically by the user. To prevent resizing, set the resize attribute to none.
Textareas will automatically resize to expand to fit their content when resize is set to auto.
You can listen for the ods-input event to determine when a textarea is updated. To see other textarea events check out the events below . You can also see how the textarea is used in forms by checking out the form section .
import '@ods/components/web.textarea';Note: You only need to import a web component once in your code, as it registers itself globally when defined, allowing you to use it anywhere within your application without needing to re-import it each time you want to use the component.
This component is still in development and cannot be imported at this time.
| Name | Description |
|---|---|
| label | The textarea's label. Alternatively, you can use the `label` attribute. |
| help-text | Text that describes how to use the input. Alternatively, you can use the `help-text` attribute. |
Please note, both DOM properties and HTML attributes are shown in the table below. Unless otherwise specified, the property and attribute names are identical.
| Property/Attribute | Reflects | Type | Default |
|---|---|---|---|
title | string | '' | |
name | string | '' | |
value | string | '' | |
label | string | '' | |
helpText | string | '' | |
errorText | string | '' | |
showCountText | boolean | false | |
placeholder | string | '' | |
rows | number | 4 | |
resize | 'none' | 'vertical' | 'auto' | 'vertical' | |
disabled | boolean | false | |
readonly | boolean | false | |
form | string | '' | |
required | boolean | false | |
minlength | number | ||
maxlength | number | ||
autocapitalize | 'off' | 'none' | 'on' | 'sentences' | 'words' | 'characters' | ||
autocorrect | string | ||
autocomplete | string | ||
autofocus | boolean | ||
enterkeyhint | 'enter' | 'done' | 'go' | 'next' | 'previous' | 'search' | 'send' | ||
spellcheck | boolean | true | |
inputmode | 'none' | 'text' | 'decimal' | 'numeric' | 'tel' | 'search' | 'email' | 'url' | ||
defaultValue | string | '' | |
validity | |||
validationMessage |
| React Event | Description | Event Detail |
|---|---|---|
| ods-blur | Emitted when the control loses focus. | -- |
| ods-change | Emitted when an alteration to the control's value is committed by the user. | -- |
| ods-focus | Emitted when the control gains focus. | -- |
| ods-input | Emitted when the control receives input. | -- |
| ods-invalid | Emitted when the form control has been checked for validity and its constraints aren't satisfied. | -- |
| Name | Description | Arguments |
|---|---|---|
| focus() | Sets focus on the textarea. | -- |
| blur() | Removes focus from the textarea. | -- |
| select() | Selects all the text in the textarea. | -- |
| scrollPosition() | Gets or sets the textarea's scroll position. | -- |
| setSelectionRange() | Sets the start and end positions of the text selection (0-based). | -- |
| setRangeText() | Replaces a range of text with a new string. | -- |
| checkValidity() | Checks for validity but does not show a validation message. Returns `true` when valid and `false` when invalid. | -- |
| getForm() | Gets the associated form, if one exists. | -- |
| reportValidity() | Checks for validity and shows the browser's validation message if the control is invalid. | -- |
| setCustomValidity() | Sets a custom validation message. Pass an empty string to restore validity. | -- |
| Name | Description |
|---|---|
| form-control | The form control that wraps the label, input, and help text. |
| form-control-label | The label's wrapper. |
| form-control-input | The input's wrapper. |
| form-control-help-text | The help text's wrapper. |
| form-control-error-text | The error text's wrapper. |
| base | The component's base wrapper. |
| textarea | The internal `<textarea>` control. |