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>
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';
Slots
Jump to heading
Learn more about using slots.
| Name | Description |
|---|---|
hint
|
Text that describes how to use the input. Alternatively, you can use the hint attribute. |
label
|
The textarea's label. Alternatively, you can use the label attribute. |
Attributes & Properties
Jump to heading
Learn more about attributes and properties.
| Name | Description | Reflects | |
|---|---|---|---|
appearanceappearance |
The textarea's visual appearance.
Type
'filled' | 'outlined' | 'filled-outlined'Default
'outlined' |
|
|
autocapitalizeautocapitalize |
Controls whether and how text input is automatically capitalized as it is entered by the user.
Type
'off' | 'none' | 'on' | 'sentences' | 'words' | 'characters' |
||
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 |
||
autocorrectautocorrect |
Indicates whether the browser's autocorrect feature is on or off.
Type
string |
||
autofocusautofocus |
Indicates that the input should receive focus on page load.
Type
boolean |
||
css |
One or more CSSResultGroup to include in the component's shadow root. Host styles are automatically prepended.
Type
CSSResultGroup | undefinedDefault
[styles, formControlStyles, sizeStyles] |
||
customStates |
Methods for setting and checking custom states.
Type
objectDefault
{ /** Adds or removes the specified custom state. / set: (customState: string, active: boolean) => { if (!Boolean(this.internals?.states)) return; try { if (active) { this.internals.states.add(customState); } else { this.internals.states.delete(customState); } } catch (e) { if (String(e).includes("must start with '--'")) { / eslint-disable-next-line / console.error('Your browser implements an outdated version of CustomStateSet. Consider using a polyfill'); } else { throw e; } } }, /* Determines whether or not the element currently has the specified state. */ has: (customState: string) => { if (!Boolean(this.internals?.states)) return false; try { return this.internals.states.has(customState); } catch { return false; } }, } |
||
defaultValuevalue |
The default value of the form control. Primarily used for resetting the form control.
Type
string |
|
|
disableddisabled |
Disables the textarea.
Type
booleanDefault
false |
||
enterkeyhintenterkeyhint |
Used to customize the label or icon of the Enter key on virtual keyboards.
Type
'enter' | 'done' | 'go' | 'next' | 'previous' | 'search' | 'send' |
||
form |
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
HTMLFormElement | null |
||
hinthint |
The textarea's hint. If you need to display HTML, use the
hint slot instead.Type
stringDefault
'' |
||
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' |
||
labellabel |
The textarea's label. If you need to display HTML, use the
label slot instead.Type
stringDefault
'' |
||
maxlengthmaxlength |
The maximum length of input that will be considered valid.
Type
number |
||
minlengthminlength |
The minimum length of input that will be considered valid.
Type
number |
||
namename |
The name of the textarea, submitted as a name/value pair with form data.
Type
string | nullDefault
null |
|
|
placeholderplaceholder |
Placeholder text to show as a hint when the input is empty.
Type
stringDefault
'' |
||
readonlyreadonly |
Makes the textarea readonly.
Type
booleanDefault
false |
|
|
requiredrequired |
Makes the textarea a required field.
Type
booleanDefault
false |
|
|
resizeresize |
Controls how the textarea can be resized.
Type
'none' | 'vertical' | 'horizontal' | 'both' | 'auto'Default
'vertical' |
|
|
rowsrows |
The number of rows to display by default.
Type
numberDefault
4 |
||
sizesize |
The textarea's size.
Type
'small' | 'medium' | 'large'Default
'medium' |
|
|
spellcheckspellcheck |
Enables spell checking on the textarea.
Type
booleanDefault
true |
||
validationTarget |
Override this to change where constraint validation popups are anchored.
Type
undefined | HTMLElement |
||
validators |
Validators are static because they have
observedAttributes, essentially attributes to "watch"
for changes. Whenever these attributes change, we want to be notified and update the validator.Type
Validator[]Default
[] |
||
value |
The current value of the input, submitted as a name/value pair with form data.
|
||
withHintwith-hint |
Used for SSR. If you're slotting in a
hint element, make sure to set this to true.Type
booleanDefault
false |
||
withLabelwith-label |
Used for SSR. If you're slotting in a
label element, make sure to set this to true.Type
booleanDefault
false |
Methods
Jump to heading
Learn more about methods.
| Name | Description | Arguments |
|---|---|---|
blur() |
Removes focus from the textarea. | |
focus() |
Sets focus on the textarea. |
options: FocusOptions
|
formStateRestoreCallback() |
Called when the browser is trying to restore element’s state to state in which case reason is "restore", or when the browser is trying to fulfill autofill on behalf of user in which case reason is "autocomplete". In the case of "restore", state is a string, File, or FormData object previously set as the second argument to setFormValue. |
state: string | File | FormData | null,
reason: 'autocomplete' | 'restore'
|
relayNativeEvent() |
Given a native event, this function cancels it and dispatches it again from the host element using the desired event options. |
event: Event,
eventOptions: EventInit
|
resetValidity() |
Reset validity is a way of removing manual custom errors and native validation. | |
scrollPosition() |
Gets or sets the textarea's scroll position. |
position: { top?: number; left?: number }
|
select() |
Selects all the text in the textarea. | |
setCustomValidity() |
Do not use this when creating a "Validator". This is intended for end users of components. We track manually defined custom errors so we don't clear them on accident in our validators. |
message: string
|
setRangeText() |
Replaces a range of text with a new string. |
replacement: string,
start: number,
end: number,
selectMode: 'select' | 'start' | 'end' | 'preserve'
|
setSelectionRange() |
Sets the start and end positions of the text selection (0-based). |
selectionStart: number,
selectionEnd: number,
selectionDirection: 'forward' | 'backward' | 'none'
|
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 |
|---|---|---|
base |
The wrapper around the <textarea> control. |
::part(base)
|
form-control-input |
The input's wrapper. |
::part(form-control-input)
|
hint |
The hint's wrapper. |
::part(hint)
|
label |
The label |
::part(label)
|
textarea |
The internal <textarea> control. |
::part(textarea)
|