2.17.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" id="input-1">
<mds-input id="input-4"></mds-input>
<input class="mds-form__input" type="text" id="input-7" disabled>
<mds-input id="input-8" disabled></mds-input>
<input class="mds-form__input" type="text" id="input-9" placeholder="First Name">
<mds-input placeholder="First Name" id="input-10"></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. |
|
String |
One of: |
|
Sets |
|
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 type |
|
Number |
— |
— |
If provided, sets the maximum number of characters allowed. |
|
Number |
— |
— |
Minimum for type |
|
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 |
One of: |
|
Alters the size of the input. |
|
Number |
Conditional based on |
— |
Sets the increment for the input. Only valid for |
|
String |
One of: |
|
Sets the |
|
String |
— |
— |
Text value for the input. |
ariaDescribedby
would be written as aria-describedby
.Setting size
, required
, and placeholder
via props:
<mds-input size="small" placeholder="First Name" id="tooltip-id" required></mds-input>
Setting value
, aria-describedby
, and readonly
via props:
<mds-input value="Jane" aria-describedy="first-name-label" id="tooltip-id" readonly></mds-input>
Setting type
, minlength
and required
via props:
<mds-input type="password" minlength="8" id="tooltip-id" required></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.