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 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

<mc-search id=one incremental placeholder=search>
  <mc-avatar slot=trailing><img alt=photo src=../../woman.jpg></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 history incremental placeholder=search>
  <mc-avatar slot=trailing><img alt=photo src=../../woman.jpg></mc-avatar>
</mc-search>


<mc-search history=id incremental placeholder=search>
  <mc-avatar slot=trailing><img alt=photo src=../../woman.jpg></mc-avatar>
</mc-search>


<mc-search history history-max=100 incremental placeholder=search>
  <mc-avatar slot=trailing><img alt=photo src=../../woman.jpg></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 incremental placeholder=search speech>
  <mc-avatar slot=trailing><img alt=photo src=../../woman.jpg></mc-avatar>
</mc-search>
            

Option groups

You can show results in multiple groups with headers
photo
<mc-search id=four incremental placeholder=search>
  <mc-avatar slot=trailing><img alt=photo src=../../woman.jpg></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 incremental placeholder=search>
  <mc-avatar slot=trailing><img alt=photo src=../../woman.jpg></mc-avatar>
  <mc-chip label="Event numbers" filter 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