Textarea
<wa-textarea>
Textareas collect data from the user and allow multiple lines of text.
<wa-textarea label="Type somethin', will ya"></wa-textarea>
This component works with standard <form> elements. Please refer to the section on form controls to learn more about form submission and client-side validation.
Examples
Jump to heading
Labels
Jump to heading
Use the label attribute to give the textarea an accessible label. For labels that contain HTML, use the label slot instead.
<wa-textarea label="Comments"></wa-textarea>
Hint
Jump to heading
Add descriptive hint to a textarea with the hint attribute. For hints that contain HTML, use the hint slot instead.
<wa-textarea label="Feedback" hint="Please tell us what you think."> </wa-textarea>
Rows
Jump to heading
Use the rows attribute to change the number of text rows that get shown.
<wa-textarea rows="2"></wa-textarea>
Placeholders
Jump to heading
Use the placeholder attribute to add a placeholder.
<wa-textarea placeholder="Type something"></wa-textarea>
Appearance
Jump to heading
Use the appearance attribute to change the textarea's visual appearance.
<wa-textarea placeholder="Type something" appearance="filled"></wa-textarea><br /> <wa-textarea placeholder="Type something" appearance="filled-outlined"></wa-textarea><br /> <wa-textarea placeholder="Type something" appearance="outlined"></wa-textarea>
Disabled
Jump to heading
Use the disabled attribute to disable a textarea.
<wa-textarea placeholder="Textarea" disabled></wa-textarea>
Value
Jump to heading
Use the value attribute to set an initial value.
<wa-textarea value="Write something awesome!"></wa-textarea>
Sizes
Jump to heading
Use the size attribute to change a textarea's size.
<wa-textarea placeholder="Small" size="small"></wa-textarea> <br /> <wa-textarea placeholder="Medium" size="medium"></wa-textarea> <br /> <wa-textarea placeholder="Large" size="large"></wa-textarea>
Prevent Resizing
Jump to heading
By default, textareas can be resized vertically by the user. To prevent resizing, set the resize attribute to none.
<wa-textarea resize="none"></wa-textarea>
Expand with Content
Jump to heading
Textareas will automatically resize to expand to fit their content when resize is set to auto.
<wa-textarea resize="auto"></wa-textarea>
Resize horizontal
Jump to heading
Textareas can be made to resize horizontally when resize is set to "horizontal"
<wa-textarea resize="horizontal"></wa-textarea>
Resize both
Jump to heading
Textareas can be made to resize both vertically and horizontally when resize is set to "both"
<wa-textarea resize="both"></wa-textarea>
Slots
Jump to heading
Learn more about using slots.
| Name | Description |
|---|---|
label
|
The textarea's label. Alternatively, you can use the label attribute. |
hint
|
Text that describes how to use the input. Alternatively, you can use the hint attribute. |
Attributes & Properties
Jump to heading
Learn more about attributes and properties.
| Name | Description | Reflects | |
|---|---|---|---|
namename |
The name of the textarea, submitted as a name/value pair with form data.
Type
string | nullDefault
null |
|
|
value |
The current value of the input, submitted as a name/value pair with form data.
|
||
defaultValuevalue |
The default value of the form control. Primarily used for resetting the form control.
Type
string |
|
|
sizesize |
The textarea's size.
Type
'small' | 'medium' | 'large'Default
'medium' |
|
|
appearanceappearance |
The textarea's visual appearance.
Type
'filled' | 'outlined' | 'filled-outlined'Default
'outlined' |
|
|
labellabel |
The textarea's label. If you need to display HTML, use the
label slot instead.Type
stringDefault
'' |
||
hinthint |
The textarea's hint. If you need to display HTML, use the
hint slot instead.Type
stringDefault
'' |
||
placeholderplaceholder |
Placeholder text to show as a hint when the input is empty.
Type
stringDefault
'' |
||
rowsrows |
The number of rows to display by default.
Type
numberDefault
4 |
||
resizeresize |
Controls how the textarea can be resized.
Type
'none' | 'vertical' | 'horizontal' | 'both' | 'auto'Default
'vertical' |
|
|
disableddisabled |
Disables the textarea.
Type
booleanDefault
false |
||
readonlyreadonly |
Makes the textarea readonly.
Type
booleanDefault
false |
|
|
formform |
By default, form controls are associated with the nearest containing
<form> element. This attribute allows you
to place the form control outside of a form and associate it with the form that has this id. The form must be in
the same document or shadow root for this to work.Type
nullDefault
null |
|
|
requiredrequired |
Makes the textarea a required field.
Type
booleanDefault
false |
|
|
minlengthminlength |
The minimum length of input that will be considered valid.
Type
number |
||
maxlengthmaxlength |
The maximum length of input that will be considered valid.
Type
number |
||
autocapitalizeautocapitalize |
Controls whether and how text input is automatically capitalized as it is entered by the user.
Type
'off' | 'none' | 'on' | 'sentences' | 'words' | 'characters' |
||
autocorrectautocorrect |
Indicates whether the browser's autocorrect feature is on or off.
Type
string |
||
autocompleteautocomplete |
Specifies what permission the browser has to provide assistance in filling out form field values. Refer to
this page on MDN for available values.
Type
string |
||
autofocusautofocus |
Indicates that the input should receive focus on page load.
Type
boolean |
||
enterkeyhintenterkeyhint |
Used to customize the label or icon of the Enter key on virtual keyboards.
Type
'enter' | 'done' | 'go' | 'next' | 'previous' | 'search' | 'send' |
||
spellcheckspellcheck |
Enables spell checking on the textarea.
Type
booleanDefault
true |
||
inputmodeinputmode |
Tells the browser what type of data will be entered by the user, allowing it to display the appropriate virtual
keyboard on supportive devices.
Type
'none' | 'text' | 'decimal' | 'numeric' | 'tel' | 'search' | 'email' | 'url' |
||
withLabelwith-label |
Used for SSR. If you're slotting in a
label element, make sure to set this to true.Type
booleanDefault
false |
||
withHintwith-hint |
Used for SSR. If you're slotting in a
hint element, make sure to set this to true.Type
booleanDefault
false |
Methods
Jump to heading
Learn more about methods.
| Name | Description | Arguments |
|---|---|---|
focus() |
Sets focus on the textarea. |
options: FocusOptions
|
blur() |
Removes focus from the textarea. | |
select() |
Selects all the text in the textarea. | |
scrollPosition() |
Gets or sets the textarea's scroll position. |
position: { top?: number; left?: number }
|
setSelectionRange() |
Sets the start and end positions of the text selection (0-based). |
selectionStart: number,
selectionEnd: number,
selectionDirection: 'forward' | 'backward' | 'none'
|
setRangeText() |
Replaces a range of text with a new string. |
replacement: string,
start: number,
end: number,
selectMode: 'select' | 'start' | 'end' | 'preserve'
|
Events
Jump to heading
Learn more about events.
| Name | Description |
|---|---|
blur |
Emitted when the control loses focus. |
change |
Emitted when an alteration to the control's value is committed by the user. |
focus |
Emitted when the control gains focus. |
input |
Emitted when the control receives input. |
wa-invalid |
Emitted when the form control has been checked for validity and its constraints aren't satisfied. |
Custom States
Jump to heading
Learn more about custom states.
| Name | Description | CSS selector |
|---|---|---|
blank |
The textarea is empty. |
:state(blank)
|
CSS parts
Jump to heading
Learn more about CSS parts.
| Name | Description | CSS selector |
|---|---|---|
label |
The label |
::part(label)
|
form-control-input |
The input's wrapper. |
::part(form-control-input)
|
hint |
The hint's wrapper. |
::part(hint)
|
textarea |
The internal <textarea> control. |
::part(textarea)
|
base |
The wrapper around the <textarea> control. |
::part(base)
|
Importing
Jump to heading
Autoloading components via projects is the recommended way to import components. If you prefer to do it manually, use one of the following code snippets.
Let your project code do the work! Sign up for free to use a project with your very own CDN — it's the fastest and easiest way to use Web Awesome.
To manually import this component from NPM, use the following code.
import '@awesome.me/webawesome/dist/components/textarea/textarea.js';
To manually import this component from React, use the following code.
import WaTextarea from '@awesome.me/webawesome/dist/react/textarea';