<wa-textarea>
Textareas collect data from the user and allow multiple lines of text.
<wa-textarea></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.
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>
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>
Use the rows
attribute to change the number of text rows that get shown.
<wa-textarea rows="2"></wa-textarea>
Use the placeholder
attribute to add a placeholder.
<wa-textarea placeholder="Type something"></wa-textarea>
Use the appearance
attribute to change the textarea's visual appearance.
<wa-textarea placeholder="Type something" appearance="filled"></wa-textarea>
Use the disabled
attribute to disable a textarea.
<wa-textarea placeholder="Textarea" disabled></wa-textarea>
Use the value
attribute to set an initial value.
<wa-textarea value="Write something awesome!"></wa-textarea>
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>
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>
Textareas will automatically resize to expand to fit their content when resize
is set to auto
.
<wa-textarea resize="auto"></wa-textarea>
Textareas can be made to resize horizontally when resize
is set to "horizontal"
<wa-textarea resize="horizontal"></wa-textarea>
Textareas can be made to resize both vertically and horizontally when resize
is set to "both"
<wa-textarea resize="both"></wa-textarea>
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. |
Learn more about attributes and properties.
Name | Description | Reflects | |
---|---|---|---|
name name |
The name of the textarea, submitted as a name/value pair with form data.
Type
string | null Default
null |
|
|
value |
The current value of the input, submitted as a name/value pair with form data.
|
||
defaultValue value |
The default value of the form control. Primarily used for resetting the form control.
Type
string |
|
|
size size |
The textarea's size.
Type
'small' | 'medium' | 'large' Default
'medium' |
|
|
appearance appearance |
The textarea's visual appearance.
Type
'filled' | 'outlined' Default
'outlined' |
|
|
label label |
The textarea's label. If you need to display HTML, use the
label slot instead.Type
string Default
'' |
||
hint hint |
The textarea's hint. If you need to display HTML, use the
hint slot instead.Type
string Default
'' |
||
placeholder placeholder |
Placeholder text to show as a hint when the input is empty.
Type
string Default
'' |
||
rows rows |
The number of rows to display by default.
Type
number Default
4 |
||
resize resize |
Controls how the textarea can be resized.
Type
'none' | 'vertical' | 'horizontal' | 'both' | 'auto' Default
'vertical' |
|
|
disabled disabled |
Disables the textarea.
Type
boolean Default
false |
||
readonly readonly |
Makes the textarea readonly.
Type
boolean Default
false |
|
|
form 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
null Default
null |
|
|
required required |
Makes the textarea a required field.
Type
boolean Default
false |
|
|
minlength minlength |
The minimum length of input that will be considered valid.
Type
number |
||
maxlength maxlength |
The maximum length of input that will be considered valid.
Type
number |
||
autocapitalize autocapitalize |
Controls whether and how text input is automatically capitalized as it is entered by the user.
Type
'off' | 'none' | 'on' | 'sentences' | 'words' | 'characters' |
||
autocorrect autocorrect |
Indicates whether the browser's autocorrect feature is on or off.
Type
string |
||
autocomplete autocomplete |
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 |
||
autofocus autofocus |
Indicates that the input should receive focus on page load.
Type
boolean |
||
enterkeyhint enterkeyhint |
Used to customize the label or icon of the Enter key on virtual keyboards.
Type
'enter' | 'done' | 'go' | 'next' | 'previous' | 'search' | 'send' |
||
spellcheck spellcheck |
Enables spell checking on the textarea.
Type
boolean Default
true |
||
inputmode inputmode |
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' |
||
withLabel with-label |
Used for SSR. If you're slotting in a
label element, make sure to set this to true .Type
boolean Default
false |
||
withHint with-hint |
Used for SSR. If you're slotting in a
hint element, make sure to set this to true .Type
boolean Default
false |
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'
|
Learn more about events.
Name | Description |
---|---|
wa-blur |
Emitted when the control loses focus. |
wa-change |
Emitted when an alteration to the control's value is committed by the user. |
wa-focus |
Emitted when the control gains focus. |
wa-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. |
Learn more about CSS custom properties.
Name | Description |
---|---|
--background-color |
The textarea's background color.
|
--border-color |
The color of the textarea's borders.
|
--border-width |
The width of the textarea's borders.
|
--box-shadow |
The shadow effects around the edges of the textarea.
|
Learn more about custom states.
Name | Description | CSS selector |
---|---|---|
blank |
The textarea is empty. | :state(blank) |
Learn more about CSS parts.
Name | Description |
---|---|
label |
The label |
form-control-input |
The input's wrapper. |
hint |
The hint's wrapper. |
textarea |
The internal <textarea> control. |
base |
The wrapper around the <textarea> control. |
The autoloader is the recommended way to import components. If you prefer to do it manually, use one of the following code snippets.
To manually import this component from the CDN, use the following code.
import 'https://early.webawesome.com/webawesome@3.0.0-alpha.9/dist/components/textarea/textarea.js';