Dropdown

Dropdown allows a user to select a value from a series of options

This component is deprecated in v5

It will be replaced by a new component. Please use the custom select component instead.

How it works

Here’s what you need to know before getting started with Dropdown component:

  • It depends on Collapse, Card and List group
  • A hidden input include data when form is submitted
  • Options can be written in HTML format and have two attributes:
    • data-value: value used to hide input
    • data-content (optional): string used to label

Example

A dropdown can be used to select between choices in a form.

Select your country
<form>
  <div class="nj-form-group">
    <div class="nj-dropdown" data-toggle="collapse" data-target="#dropdownSimpleCountry" tabindex="0">
      <input type="hidden">
      <div class="nj-dropdown__label">Select your country</div>
      <div class="nj-dropdown__list nj-collapse" id="dropdownSimpleCountry">
        <div class="nj-card border">
          <div class="nj-list-group nj-list-group--no-border nj-list-group--sm my-1">
            <button type="button" class="nj-list-group__item" data-value="fr">France</button>
            <button type="button" class="nj-list-group__item" data-value="it">Italy</button>
            <button type="button" class="nj-list-group__item" data-value="be">Belgium</button>
            <button type="button" class="nj-list-group__item" data-value="uk">United Kingdom</button>
            <button type="button" class="nj-list-group__item" data-value="sp">Spain</button>
          </div>
        </div>
      </div>
    </div>
  </div>
</form>

Advanced example

Use optional data-content tag for HTML options

Select your country
<form>
  <div class="nj-dropdown" data-toggle="collapse" data-target="#dropdownAdvancedCountry" tabindex="0">
    <input type="hidden">
    <div class="nj-dropdown__label">Select your country</div>
    <div class="nj-dropdown__list nj-collapse" id="dropdownAdvancedCountry">
      <div class="nj-card border">
        <div class="nj-list-group nj-list-group--no-border nj-list-group--sm my-1">
          <button type="button" class="nj-list-group__item" data-value="fr">
            <img src="https://cdn.countryflags.com/thumbs/france/flag-square-250.png" height="24" width="24" class="rounded-circle">
            <span class="ml-2" data-content>France</span>
          </button>
          <button type="button" class="nj-list-group__item" data-value="it">
            <img src="https://cdn.countryflags.com/thumbs/italy/flag-square-250.png" height="24" width="24" class="rounded-circle">
            <span class="ml-2" data-content>Italy</span>
          </button>
          <button type="button" class="nj-list-group__item" data-value="be">
            <img src="https://cdn.countryflags.com/thumbs/belgium/flag-square-250.png" height="24" width="24" class="rounded-circle">
            <span class="ml-2" data-content>Belgium</span>
          </button>
          <button type="button" class="nj-list-group__item" data-value="uk">
            <img src="https://cdn.countryflags.com/thumbs/united-kingdom/flag-square-250.png" height="24" width="24" class="rounded-circle">
            <span class="ml-2" data-content>United Kingdom</span>
          </button>
          <button type="button" class="nj-list-group__item" data-value="sp">
            <img src="https://cdn.countryflags.com/thumbs/spain/flag-square-250.png" height="24" width="24" class="rounded-circle">
            <span class="ml-2" data-content>Spain</span>
          </button>
        </div>
      </div>
    </div>
  </div>
</form>