Textarea

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.

Slots

NameDescription
labelThe textarea's label. Alternatively, you can use the `label` attribute.
help-textText that describes how to use the input. Alternatively, you can use the `help-text` attribute.

Properties

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/AttributeReflectsTypeDefault
title
string''
name
string''
value
string''
label
string''
helpText
help-text
string''
errorText
error-text
string''
showCountText
show-count-text
booleanfalse
placeholder
string''
rows
number4
resize
'none' | 'vertical' | 'auto''vertical'
disabled
booleanfalse
readonly
booleanfalse
form
string''
required
booleanfalse
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
booleantrue
inputmode
'none' | 'text' | 'decimal' | 'numeric' | 'tel' | 'search' | 'email' | 'url'
defaultValue
string''
validity
validationMessage

Events

React EventDescriptionEvent Detail
ods-blurEmitted when the control loses focus.--
ods-changeEmitted when an alteration to the control's value is committed by the user.--
ods-focusEmitted when the control gains focus.--
ods-inputEmitted when the control receives input.--
ods-invalidEmitted when the form control has been checked for validity and its constraints aren't satisfied.--

Methods

NameDescriptionArguments
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.--

Parts

NameDescription
form-controlThe form control that wraps the label, input, and help text.
form-control-labelThe label's wrapper.
form-control-inputThe input's wrapper.
form-control-help-textThe help text's wrapper.
form-control-error-textThe error text's wrapper.
baseThe component's base wrapper.
textareaThe internal `<textarea>` control.

Search