Text area
Use in a form context
Import
Import the settings, the text area and the fields scss files.
@import 'settings-tools/all-settings';@import 'components/c.textarea';@import 'components/c.fields';
Note that the import order is important to get the right rendering of the component.
Usage
To use the text area in your form, you must use the following 3 CSS classes:
mc-field
on containermc-field__label
on label- and
mc-field__input
in addition of themc-textarea
class on the standardtextarea
html tag:
<div class="mc-field"> <label class="mc-field__label" for="foo"> Label </label> <textarea class="mc-field__input mc-textarea" name="foo" id="foo" rows="4" placeholder="placeholder" ></textarea></div>
Behaviors
Help text
You have the possibility to define a help text when using your text area.
For this you have to add a span with the mc-field__help
class below the label.
<label class="mc-field__label"> Label </label><span id="helptext" class="mc-field__help"> Help text </span>
When using a help text you must comply with the following accessibility rules:
- the span
mc-field__help
must always have anid
- the
aria-describedby
attribute must be added on the text area element and must refer to the id of the help text
Requirement
When the text area is mandatory you must specify it to the user.
For this you have to add a span with the class mc-field__requirement
right after the label.
<label class="mc-field__label"> Label <span class="mc-field__requirement"> mandatory </span></label>
When the text area is mandatory the required
attribute must be added on the text area element
States and Validation
Valid
To indicate that a field is valid, the is-valid
class must be added to the text area element.
Invalid
To indicate that a field is not valid several steps are to be implemented:
- Add the
is-invalid
class and thearia-invalid
attribute to the text area element - You can add in addition a text detailing the error. This text must be added in a span with the class
mc-field__error-message
and positioned below the field
If you use an error message you must comply with the following accessibility rules:
- the span
mc-field__error-message
must always have anid
- the
aria-describedby
attribute must be added on the text area element and must refer to the id of the error message
Disabled
To indicate that text area is disabled, the disabled
attribute must be added to the text area element.
Use outside a form
In some cases you may need to use the text field outside of a form. To do this, the way to implement it is as follows:
Import
@import 'settings-tools/all-settings';@import 'components/c.textarea';
Usage
Apply the classes mc-textarea
on a standard textarea
html tag:
<textarea class="mc-textarea" name="single" id="single" rows="4" placeholder="placeholder" aria-label="The label of your textarea"></textarea>
Accessibility and semantic
Provide minlength and/or maxlength attributes if a text length is required from the user
Never use the resize: none attribute for standards forms