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.
<!-- Default -->
<input class="mds-form__input" type="text" id="input-id">
<!-- With Placeholder Text -->
<input class="mds-form__input" type="text" id="input-id" placeholder="First Name">
<!-- Disabled -->
<input class="mds-form__input" type="text" id="input-id" disabled>
<!-- Default -->
<mds-input id="input-id"></mds-input>
<!-- With Placeholder Text -->
<mds-input placeholder="First Name" id="input-id"></mds-input>
<!-- Disabled -->
<mds-input id="input-id" disabled></mds-input>
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="first-name"> First Name </label>
<input class="mds-form__input" type="text" id="first-name" placeholder="First Name" />
</div>
<!-- Web Component -->
<mds-field-group>
<mds-label for="first-name"> First Name </mds-label>
<mds-input id="first-name" placeholder="First Name"></mds-input>
</mds-field-group>
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="input-id" placeholder="First Name">
<mds-input size="small" placeholder="First Name" id="input-id"></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. |
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 id, like microcopy or a field errors, whose content contains information about the input. |
|
String |
One of: |
|
Sets |
|
String |
— |
— |
Adds |
|
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 |
|
Boolean |
— |
— |
Sets the |
|
String |
One of: |
|
Sets the |
|
String |
— |
— |
Text value for the input. |
Setting size
, required
, id
, and placeholder
via props:
<mds-input size="small" placeholder="First Name" id="input-id" required></mds-input>
Setting value
, aria-describedby
, id
, and readonly
via props:
<mds-input value="Jane" aria-describedy="first-name-microcopy" id="input-id" readonly></mds-input>
Setting type
, minlength
, id
, and required
via props:
<mds-input type="password" minlength="8" id="input-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.