2.34.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.
<!-- Default -->
<textarea class="mds-form__textarea" id="textarea-id"></textarea>
<!-- With Placeholder Text -->
<textarea class="mds-form__textarea" id="textarea-id" placeholder="Tell us more here..."></textarea>
<!-- Disabled -->
<textarea class="mds-form__textarea" id="textarea-id" disabled></textarea>
<!-- Default -->
<mds-textarea id="textarea-id"></mds-textarea>
<!-- With Placeholder Text -->
<mds-textarea id="textarea-id" placeholder="Tell us more here..."></mds-textarea>
<!-- Disabled -->
<mds-textarea id="textarea-id" disabled></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.
<!-- HTML -->
<div class="mds-form__field-group">
<label class="mds-form__label" for="comments">Comments</label>
<textarea class="mds-form__textarea" id="comments"></textarea>
</div>
<!-- Web Component -->
<mds-field-group>
<mds-label for="comments">Comments</mds-label>
<mds-textarea id="comments"></mds-textarea>
</mds-field-group>
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"></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. |
|
|
Adjusts styling to render a touch textarea. |
Use this mixin to create media queries in your product styles to switch textareas to their touch variation.
@include mds-textarea-touch-properties();
For example, switching to the touch variation on screens with a max-width
of 500px
:
// Your product SCSS
@media screen and (max-width: 500px) {
@include mds-textarea-touch-properties();
}
max-width
, pointer: coarse
is another helpful method for targeting touch screen devices.@include mds-form-all-touch-properties();
mixin for efficiency.When setting props as attributes on a custom HTML element, use kebab-case
instead of camelCase
.
Prop
|
Type
|
Validation
|
Default
|
Description
|
---|---|---|---|---|
|
String |
— |
— |
A space-separated list of class names that will be appended to the default |
|
String |
— |
— |
A space-separated list of element |
|
Boolean |
— |
— |
Adds the |
|
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 |
|
Number |
— |
— |
Sets the number of visible text lines. |
|
String |
One of: |
|
Alters the size of the textarea. |
|
String |
— |
— |
The content for the textarea. |
Setting id
, size
, required
, and placeholder
via props:
<mds-textarea id="textarea-id" size="small" placeholder="Comments" required></mds-textarea>
Setting id
, ariaInvalid
, and minlength
via props:
<mds-textarea id="textarea-id" aria-invalid minlength="40"></mds-textarea>
Setting id
and text
via props:
<mds-textarea id="textarea-id" text="Text area content."></mds-textarea>
On touch screens, :hover
states “stick” after tapping an interactive element. To counter this behavior, MDS provides a mixin that resets component hover states to their default styles:
@include mds-sticky-hover-reset();
The mixin uses a media query based on hover: none
to target touch screen devices and includes resets for Buttons, Checkboxes, Inputs, List Groups, Radio Buttons, Search Fields, Selects, Switches, and Textareas. You can apply this mixin within your product’s media queries along with other MDS touch styles, for example:
// Your product SCSS
@media screen and (max-width: 500px) {
@include mds-sticky-hover-reset();
@include mds-componentName-touch-properties();
// The rest of your product’s responsive/touch styles...
}
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
.