2.14.0
Search fields allow a user to type in exactly what they’re looking for.
Use when search is a major function of a page.
<div class="mds-search-field " role="search">
<input type="text" class="mds-search-field__input" aria-label="Search" placeholder="Search for Security">
<svg class="mds-icon mds-search-field__search-icon" aria-hidden="true">
<use xlink:href="/icons/mds.svg#search--s">
</use>
</svg>
<span class="mds-search-field__input-focus-outline"></span>
</div>
<mds-search-field placeholder="Search for Security"></mds-search-field>
<div class="mds-search-field " role="search">
<input type="text" class="mds-search-field__input" aria-label="Search" placeholder="Search for Security" disabled>
<svg class="mds-icon mds-search-field__search-icon" aria-hidden="true">
<use xlink:href="/icons/mds.svg#search--s">
</use>
</svg>
<span class="mds-search-field__input-focus-outline"></span>
</div>
<mds-search-field placeholder="Search for Security" disabled></mds-search-field>
Use in most cases, when search is a supplemental function on a page.
<div class="mds-search-field mds-search-field--secondary" role="search">
<input type="text" class="mds-search-field__input" aria-label="Search" placeholder="Search for Security">
<svg class="mds-icon mds-search-field__search-icon" aria-hidden="true">
<use xlink:href="/icons/mds.svg#search--s">
</use>
</svg>
<span class="mds-search-field__input-focus-outline"></span>
</div>
<mds-search-field variation="secondary" placeholder="Search for Security"></mds-search-field>
<div class="mds-search-field mds-search-field--secondary" role="search">
<input type="text" class="mds-search-field__input" aria-label="Search" placeholder="Search for Security" disabled>
<svg class="mds-icon mds-search-field__search-icon" aria-hidden="true">
<use xlink:href="/icons/mds.svg#search--s">
</use>
</svg>
<span class="mds-search-field__input-focus-outline"></span>
</div>
<mds-search-field variation="secondary" placeholder="Search for Security" disabled></mds-search-field>
Sizing affects search field size, text size, icon size, and internal spacing. The default size is medium, and you can use modifier classes or props to make the search field smaller or larger.
<div class="mds-search-field mds-search-field--secondary mds-search-field--small" role="search">
<input type="text" class="mds-search-field__input" aria-label="Search" placeholder="Search for Security">
<svg class="mds-icon mds-search-field__search-icon" aria-hidden="true">
<use xlink:href="/icons/mds.svg#search--s">
</use>
</svg>
<span class="mds-search-field__input-focus-outline"></span>
</div>
<mds-search-field variation="secondary" size="small" placeholder="Search for Security"></mds-search-field>
remove--s
, allows the user to clear their entry. For live search, clicking the remove icon also clears the results of the current search.focus
. This is default IE11 behavior and a known issue, teams are still encouraged to use search fields in production.
Class
|
Applies to
|
Outcome
|
---|---|---|
|
|
Renders the search field using the secondary style. |
|
|
Adjusts styling to render a small search field. |
|
|
Adjusts styling to render a large search field. |
Prop
|
Type
|
Validation
|
Default
|
Description
|
---|---|---|---|---|
|
String |
Required |
“Search” |
Text value for the |
|
String |
— |
— |
A space-separated list of class names that will be appended to the default |
|
Boolean |
— |
|
If |
|
String |
— |
— |
The |
|
String |
— |
“Search...” |
Adds placeholder text. |
|
String |
— |
— |
Text value for the search field. If omitted, the placeholder will be displayed by default. |
|
String |
Enum: |
|
Alters the size of the search field. |
|
String |
Enum: |
|
Sets the search field variation. |
ariaLabel
would be written as aria-label
.
Method Name
|
Description
|
---|---|
|
Removes the value from the search field. |
Setting variation
and size
via props:
<mds-search-field variation="secondary" size="small"></mds-search-field>
Setting placeholder
and value
via props:
<mds-search-field placeholder="Custom Placeholder Text" value="Predefined Value"></mds-search-field>
aria-label
attribute to define the text that assistive technology uses to describe the search field element. By default it is set to “Search”.role="search"
.