3.0.0-alpha.4 Alpha
Light Dark Light Dark System Search /

Textarea

<wa-textarea> Since 2.0 stable

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.

Examples

Labels

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>

Help Text

Add descriptive help text to a textarea with the help-text attribute. For help texts that contain HTML, use the help-text slot instead.

<wa-textarea label="Feedback" help-text="Please tell us what you think."> </wa-textarea>

Rows

Use the rows attribute to change the number of text rows that get shown.

<wa-textarea rows="2"></wa-textarea>

Placeholders

Use the placeholder attribute to add a placeholder.

<wa-textarea placeholder="Type something"></wa-textarea>

Filled Textareas

Add the filled attribute to draw a filled textarea.

<wa-textarea placeholder="Type something" filled></wa-textarea>

Disabled

Use the disabled attribute to disable a textarea.

<wa-textarea placeholder="Textarea" disabled></wa-textarea>

Sizes

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

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

Textareas will automatically resize to expand to fit their content when resize is set to auto.

<wa-textarea resize="auto"></wa-textarea>

Slots

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.

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'
filled
filled
Draws a filled textarea.
Type boolean
Default false
label
label
The textarea's label. If you need to display HTML, use the label slot instead.
Type string
Default ''
helpText
help-text
The textarea's help text. If you need to display HTML, use the help-text 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' | '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
withHelpText
with-help-text
Used for SSR. If you're slotting in a help-text element, make sure to set this to true.
Type boolean
Default false

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

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.

CSS custom properties

Name Description
--background-color
The textarea's background color.
--border-color
The color of the textarea's borders.
--border-radius
The border radius of the textarea's corners.
--border-style
The style 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.

CSS parts

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.
base The component's base wrapper.
textarea The internal <textarea> control.

Importing

The autoloader is the recommended way to import components. If you prefer to do it manually, use one of the following code snippets.

CDN npm React

To manually import this component from the CDN, use the following code.

import 'https://early.webawesome.com/webawesome@3.0.0-alpha.4/dist/components/textarea/textarea.js';
Coming soon! Coming soon!
    No results