2.8.6 #Components.dropdown.search-with-no-results-and-create-item-action Search with no results and create item action

Toggle example guides Toggle HTML markup

The create action button overrides the default "No results" message.

JavaScript is required for:

  • Checking/Unchecking the checkbox on row click
  • Filtering the menu items based on the search input
  • Updating the button text with the number of selected items
  • Highlighting items
  • Executing the create item action
  • Updating the create item text with the search input text
  • Hiding the "No results" message

Browser support: IE10+, Safari6+, Firefox30+, Chrome30+

Markup
<div class="sb-form-control">
  <label class="sb-label" for="dropdown-id-search">Select options or create new</label>
  <div class="sb-dropdown sb-dropdown--open" id="dropdown-id-search">
    <div class="sb-dropdown__button sb-form-control__input sb-form-control__input--icon-right">
      <button class="sb-input" aria-label="One option selected">
        Select options
      </button>
      <svg class="sb-icon" viewBox="-5 -5 16 16"><path d="M0 0l3.5 4L7 0H0"></svg>
    </div>
    <ul class="sb-dropdown__menu" role="listbox">
      <li class="sb-dropdown__search" role="search">
        <input class="sb-input" id="input-id-1" placeholder="Search here ..." value="er" aria-label="Search">
      </li>
      <li>
        <button class="sb-dropdown__menu-item sb-dropdown__create-item-action" tabindex="-1">
          <svg class="sb-icon" viewBox="0 0 16 16">
            <path d="M6.5 12a5.5 5.5 0 1 0 0-11 5.5 5.5 0 0 0 0 11zm0 1a6.5 6.5 0 1 1 0-13 6.5 6.5 0 0 1 0 13zM7 6V3H6v3H3v1h3v3h1V7h3V6H7z" />
          </svg>
          Create "er" as new option
        </button>
      </li>
    </ul>
  </div>
</div>
Source: components/_dropdown.scss, line 383