2.11.0
Textareas allow a user to input multiple lines of text.
See Forms for guidance on composing full forms.
Use when soliciting multiple lines of text.
<textarea class="mds-form__textarea"></textarea>
<mds-textarea></mds-textarea>
<textarea class="mds-form__textarea" disabled></textarea>
<mds-textarea disabled></mds-textarea>
<textarea class="mds-form__textarea" placeholder="Tell us more here..."></textarea>
<mds-textarea placeholder="Tell us more here..."></mds-textarea>
Always wrap grouped form elements in a mds-form__field-group
container. See the Forms composition section for more guidelines on constructing forms.
<div class="mds-form__field-group">
<label class="mds-form__label" for="comments">Comments</label>
<textarea class="mds-form__textarea" id="comments"></textarea>
</div>
Sizing affects textarea size, text size and internal spacing. The default size is medium, and you can use modifier classes or props to make the textarea smaller or larger.
<textarea class="mds-form__textarea mds-form__textarea--small" id="small-textarea" placeholder="Textarea"></textarea>
<mds-textarea placeholder="Textarea" size="small" id="small-textarea-wc"></mds-textarea>
focus
. This is default behavior and a known issue, teams are still encouraged to use textareas in production.
Class
|
Applies to
|
Outcome
|
---|---|---|
|
|
Adjusts styling to render a small textarea. |
|
|
Adjusts styling to render a large textarea. |
Prop
|
Type
|
Validation
|
Default
|
Description
|
---|---|---|---|---|
|
String |
— |
— |
A space-separated list of element id, like microcopy or a field errors, whose content contains information about the textarea. |
|
Boolean |
— |
— |
Adds the |
|
String |
Enum: |
— |
Sets whether text should be automatically capitalized. Note: non-standard attribute and applies for iOS devices only. |
|
String |
Enum: |
— |
Adds |
|
String |
— |
— |
A space-separated list of class names that will be appended to the default |
|
Boolean |
— |
|
If |
|
String |
Required |
— |
The |
|
Number |
— |
— |
If provided, sets the maximum number of characters allowed. |
|
Number |
— |
— |
If provided, sets the minimum number of characters allowed. |
|
String |
— |
— |
Adds the |
|
String |
— |
— |
Adds placeholder text. |
|
Boolean |
— |
|
Adds the |
|
Boolean |
— |
|
If true, adds the |
|
Number |
— |
— |
Sets the number of visible text lines. |
|
String |
Enum: |
— |
Alters the size of the textarea. |
|
String |
Enum: |
— |
Specifies whether the textarea is subject to spell checking by the underlying browser/OS. |
|
String |
— |
— |
The content for the textarea. |
ariaDescribedby
would be written as aria-describedby
.Setting size, required status, and placeholder text:
<mds-textarea size="small" placeholder="Comments" required="true"></mds-textarea>
Setting aria-invalid
and minlength
:
<mds-textarea aria-invalid="true" minlength="40"></mds-textarea>
Setting the text content:
<mds-textarea text="Text area content."></mds-textarea>
minlength
property in Edge v17+, if required
isn’t set, and the user didn’t specify a value, minlength
has no affect.aria-describedby
attribute on each textarea
that has an .mds-form__microcopy
or an .mds-form__field-error
component providing additional information. The value of the aria-describedby
attribute must match the id
attribute on the .mds-form__microcopy
or .mds-form__field-error
component.for
attribute on each label
with a value matching the id
attribute on the corresponding textarea
.