2.11.0
Inputs allow a user to input and interact with data.
See Forms for guidance on composing full forms.
Use to solicit a short, single line of text or a number.
<input class="mds-form__input" type="text">
<mds-input></mds-input>
<input class="mds-form__input" type="text" disabled>
<mds-input disabled></mds-input>
<input class="mds-form__input" type="text" placeholder="First Name">
<mds-input placeholder="First Name"></mds-input>
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="first-name">First Name</label>
<input class="mds-form__input" type="text" id="first-name" placeholder="First Name" />
</div>
Sizing affects input size, text size and internal spacing. The default size is medium, and you can use modifier classes or props to make the input smaller or larger.
<input class="mds-form__input mds-form__input--small" type="text" id="small-text-box" placeholder="First Name">
<mds-input size="small" placeholder="First Name" id="small-text-box-wc"></mds-input>
focus
. This is default behavior and a known issue, teams are still encouraged to use text boxes in production.
Class |
Applies to |
Outcome |
---|---|---|
|
|
Applies small styles to the input. |
|
|
Applies large styles to the input. |
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 input. |
|
Boolean |
–– |
–– |
If |
|
String |
–– |
–– |
Adds |
|
String |
–– |
–– |
A space-separated list of class names that will be appended to the default |
|
Boolean |
–– |
|
If |
|
String |
Required |
–– |
The |
|
Number |
–– |
–– |
Maximum for types |
|
Number |
–– |
–– |
If provided, sets the maximum number of characters allowed. |
|
Number |
–– |
–– |
Minimum for types |
|
Number |
–– |
–– |
If provided, sets the minimum number of characters allowed. |
|
String |
–– |
–– |
Adds the |
|
String |
–– |
–– |
RegExp pattern for value to be validated against. |
|
String |
–– |
–– |
Adds placeholder text. |
|
Boolean |
–– |
|
Adds the |
|
Boolean |
–– |
|
If true, adds the |
|
String |
Enum: |
|
Alters the size of the input. |
|
Number |
Conditional based on |
–– |
Sets the increment for the input. Only valid for |
|
String |
Enum: |
|
Sets the |
|
String |
–– |
–– |
Text value for the input. |
ariaDescribedby
would be written as aria-describedby
.Setting size, required status, and placeholder text:
<mds-input size="small" placeholder="First Name" required="true"></mds-input>
Setting the value and aria-describedby
, and making the input read only:
<mds-input value="Jane" aria-describedy="first-name-label" readonly="true"></mds-input>
Setting the type and minimum length:
<mds-input type="password" minlength="8" required="true"></mds-input>
minlength
property in Edge v17+, if required
isn’t set, and the user didn’t specify a value, minlength
has no affect.placeholder
text to provide an example of the type of input you need from the user. For example, if you need a phone number in a certain format, include (123) 456-7890
as placeholder text. aria-describedby
attribute on each input
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 input
.placeholder
text in place of a label
. See Labels for more information.