Welcome Getting started Layout styles github-circle-black-transparent Source
Components
Badges
App bars
Bottom app bars Top app bars
Buttons
Common buttons FAB Icon buttons Segmented buttons
Cards Carousel Checkboxes Chips Date pickers Dialogs Forms Icons Lists Menus Navigation Progress indicators Pull to refresh Radios Search Selects
Sheets
Bottom sheets Side sheets
Sliders Snackbars Switches Tables Tabs Text fields Time pickers Tooltips Utilities
home apps Buttons palette Two
Materially
github-circle-black-transparent

Search

Search allows users to enter a keyword or phrase and get relevant information. It’s an alternative to other forms of navigation
Material Design Guidelines: Search
Standard
By default the search event only triggers on enter key. Look at next example for how to change that.
photo
<!-- incremental debounces the input and fires the search
  If not present then the enter key will fire the search -->
<mc-search id="one" placeholder="search" incremental>
  <mc-avatar slot="trailing"><img alt="photo" src="../../woman.jpg"></img></mc-avatar>
  <mc-search-option-group id="secondary" label="Secondary"></mc-search-option-group>
</mc-search>
            
// get selected value and object
searchOne.addEventListener('change', () => console.log(searchOne.selected, searchOne.selectedObject));
  console.log('okokokko')
document.querySelector('mc-search#one').addEventListener('search', event => {
  // set results
  event.target.results = [{
    value: 'one',
    display: 'One',
  },{
    value: 'two',
    display: 'Two',

    // specify container to place in mc-search-option-group#secondary
    container: 'secondary'
  }].filter(v => v.display.toLocaleLowerCase().includes(event.target.value));


  // set suggestions for searches
  event.target.suggestions = [{
    value: 'one'
  },{
    value: 'two'
  }].filter(v => v.display.toLocaleLowerCase().includes(event.target.value));
});
            

History

Sow historical suggestions. History is stored in localstorage to maintains across refreshes
photo
<mc-search placeholder="search" incremental history>
  <mc-avatar slot="trailing"><img alt="photo" src="../../woman.jpg"></img></mc-avatar>
</mc-search>

<!-- set history id to use the same history for multiple searches -->
<mc-search placeholder="search" incremental history="id">
  <mc-avatar slot="trailing"><img alt="photo" src="../../woman.jpg"></img></mc-avatar>
</mc-search>

<!-- set history max. Default: 100 -->
<mc-search placeholder="search" incremental history history-max="100">
  <mc-avatar slot="trailing"><img alt="photo" src="../../woman.jpg"></img></mc-avatar>
</mc-search>
            
// clear search history
document.querySelector('mc-search').clearHistory();
            

Speech

Speech recognition will only show if browser supports it
photo
<mc-search placeholder="search" incremental speech>
  <mc-avatar slot="trailing"><img alt="photo" src="../../woman.jpg"></img></mc-avatar>
</mc-search>
            

Option groups

You can show results in multiple groups with headers
photo
<mc-search id="four" placeholder="search" incremental>
  <mc-avatar slot="trailing"><img alt="photo" src="../../woman.jpg"></img></mc-avatar>
  <mc-search-option-group id="primary" label="Primary"></mc-search-option-group>
  <mc-search-option-group id="secondary" label="Secondary"></mc-search-option-group>
</mc-search>
            

Filter chips

Add chip filters to search component
photo
<mc-search id="five" placeholder="search" incremental>
  <mc-avatar slot="trailing"><img alt="photo" src="../../woman.jpg"></img></mc-avatar>
  <mc-chip filter label="Event numbers" slot="chips"></mc-chip>
  <mc-search-container id="primary" label="Primary"></mc-search-container>
  <mc-search-container id="secondary" label="Secondary"></mc-search-container>
</mc-search>
            
menu home apps Get started