Dropdown

Dropdowns contain and give access to a list of buttons or other elements hidden by default. They are commonly used for menus in web applications.

Using Dropdowns

A dropdown must be associated to an activator, commonly a button, which, at the time of being clicked, expands the dropdown. Activator and dropdown should be contained in a div with an m-dropdown class, or otherwise, the activator must reference the dropdown with a data-target attribute.

Use the m-dropdown__trigger class on your activator button to make the chevron appear.

Example 1

Trigger and dropdown enclosed in the same div.

<div class="m-dropdown">
  <button class="a-btn m-dropdown__trigger">Dropdown component</button>
  <div class="m-dropdown__menu">
    <a class="m-dropdown__menu-item" href="#">Element 1</a>
    <a class="m-dropdown__menu-item" href="#">Element 2</a>
    <a class="m-dropdown__menu-item" href="#">Element 3</a>
  </div>
</div>
<div class="m-dropdown">
  <button class="a-btn m-dropdown__trigger -active">Dropdown component</button>
  <div class="m-dropdown__menu -active">
    <a class="m-dropdown__menu-item" href="#">Element 1</a>
    <a class="m-dropdown__menu-item" href="#">Element 2</a>
    <a class="m-dropdown__menu-item" href="#">Element 3</a>
  </div>
</div>

Example 2

Dropdown referenced by a data-target attribute in the activator.

There is no need for proximity between elements.

<div class="-p--3">
  <button class="a-btn m-dropdown__trigger" data-target="#dropdown-1">Dropdown component</button>
  <p class="-text">There is no need for proximity between elements.</p>
  <div class="m-dropdown__menu" id="dropdown-1">
    <a class="m-dropdown__menu-item" href="#">Element 1</a>
    <a class="m-dropdown__menu-item" href="#">Element 2</a>
    <a class="m-dropdown__menu-item" href="#">Element 3</a>
    <a class="m-dropdown__menu-item" href="#">Element 4</a>
  </div>
</div>

There is no need for proximity between elements.

<div class="-p--3">
  <button class="a-btn m-dropdown__trigger -active" data-target="#dropdown-1">Dropdown component</button>
  <p class="-text">There is no need for proximity between elements.</p>
  <div class="m-dropdown__menu -active" id="dropdown-1">
    <a class="m-dropdown__menu-item" href="#">Element 1</a>
    <a class="m-dropdown__menu-item" href="#">Element 2</a>
    <a class="m-dropdown__menu-item" href="#">Element 3</a>
    <a class="m-dropdown__menu-item" href="#">Element 4</a>
  </div>
</div>

Example 3

Dropdown on hover is only supported when trigger and dropdown elements are enclosed in the same div. Use the m-dropdown__hover class to achieve this.

<div class="m-dropdown m-dropdown__hover">
  <button class="a-btn m-dropdown__trigger">Dropdown component</button>
  <div class="m-dropdown__menu">
    <a class="m-dropdown__menu-item" href="#">Element 1</a>
    <a class="m-dropdown__menu-item" href="#">Element 2</a>
    <a class="m-dropdown__menu-item" href="#">Element 3</a>
  </div>
</div>

Divider

Several menu items can be arranged together by using a divider. Use the a-divider component.

Example

<div class="m-dropdown__menu">
  <a class="m-dropdown__menu-item" href="#">Element 1</a>
  <a class="m-dropdown__menu-item" href="#">Element 2</a>
  <a class="m-dropdown__menu-item" href="#">Element 3</a>
  <div class="a-divider"></div>
  <a class="m-dropdown__menu-item" href="#">Element 4</a>
</div>

Menu item states

Each menu item can be in one of four item states normal, active, disabled and hover.

Example

<div class="m-dropdown__menu">
  <a class="m-dropdown__menu-item" href="#">Normal element</a>
  <a class="m-dropdown__menu-item -active" href="#">Active element</a>
  <a class="m-dropdown__menu-item -disabled" href="#">Disabled element</a>
  <a class="m-dropdown__menu-item -hover" href="#">Hovered item</a>
</div>

Icons

Dropdown component has been developed to support Chi icons in the menu items.

Example

<div class="m-dropdown__menu">
  <a class="m-dropdown__menu-item" href="#">
    <i class="a-icon icon-file-outline"></i>New
  </a>
  <a class="m-dropdown__menu-item -disabled" href="#">
    <i class="a-icon icon-arrow-to-bottom"></i>Save
  </a>
  <div class="a-divider"></div>
  <a class="m-dropdown__menu-item" href="#">
    <i class="a-icon icon-mail"></i>Send
  </a>
  <a class="m-dropdown__menu-item -active" href="#">
    <i class="a-icon icon-shopping-cart"></i>Buy
  </a>
  <a class="m-dropdown__menu-item" href="#">
    <i class="a-icon icon-users"></i>Share
  </a>
  <div class="a-divider"></div>
  <a class="m-dropdown__menu-item" href="#">
    <i class="a-icon icon-logout"></i>Logout
  </a>
</div>

Form elements

Several kinds of form items can be added inside the dropdown menu.

Search box

This search box is a special kind of text input prepared to be located on top of the menu-item. It has slightly smaller padding at the sides.

<div class="m-dropdown__menu">
  <div class="a-inputWrapper -icon--left m-dropdown__menu-item">
    <input class="a-input" type="text" placeholder="Search">
    <i class="a-icon icon-search -text--muted"></i>
  </div>
  <a class="m-dropdown__menu-item" href="#">Element 1</a>
  <a class="m-dropdown__menu-item" href="#">Element 2</a>
  <a class="m-dropdown__menu-item" href="#">Element 3</a>
  <a class="m-dropdown__menu-item" href="#">Element 4</a>
</div>

Checkboxes

Two versions of checkboxes, with and without icon have been included in the library to be used as menu items.

Base
<div class="m-dropdown__menu">
  <div class="m-dropdown__menu-item">
    <input class="a-input" type="checkbox" id="checkbox1">
    <label for="checkbox1"></label>
    <label class="-text" for="checkbox1">Element 1</label>
  </div>
  <div class="m-dropdown__menu-item">
    <input class="a-input" type="checkbox" id="checkbox2" disabled>
    <label for="checkbox2"></label>
    <label class="-text" for="checkbox2">Element 2</label>
  </div>
  <div class="m-dropdown__menu-item">
    <input class="a-input" type="checkbox" id="checkbox3" checked>
    <label for="checkbox3"></label>
    <label class="-text" for="checkbox3">Element 3</label>
  </div>
  <div class="m-dropdown__menu-item">
    <input class="a-input" type="checkbox" id="checkbox4">
    <label for="checkbox4"></label>
    <label class="-text" for="checkbox4">Element 4</label>
  </div>
</div>
With Icons
<div class="m-dropdown__menu">
  <div class="m-dropdown__menu-item">
    <input class="a-input" type="checkbox" id="checkbox1">
    <label for="checkbox1"></label>
    <label class="-text" for="checkbox1">
      <i class="a-icon icon-logo-centurylink"></i>
      Element 1
    </label>
  </div>
  <div class="m-dropdown__menu-item">
    <input class="a-input" type="checkbox" id="checkbox2" disabled>
    <label for="checkbox2"></label>
    <label class="-text" for="checkbox2">
      <i class="a-icon icon-logo-centurylink"></i>
      Element 2
    </label>
  </div>
  <div class="m-dropdown__menu-item">
    <input class="a-input" type="checkbox" id="checkbox3" checked>
    <label for="checkbox3"></label>
    <label class="-text" for="checkbox3">
      <i class="a-icon icon-logo-centurylink"></i>
      Element 3
    </label>
  </div>
  <div class="m-dropdown__menu-item">
    <input class="a-input" type="checkbox" id="checkbox4">
    <label for="checkbox4"></label>
    <label class="-text" for="checkbox4">
      <i class="a-icon icon-logo-centurylink"></i>
      Element 4
    </label>
  </div>
</div>

Plain Text

Use a span tag to include text without rendering as a link.

<div class="m-dropdown__menu">
  <span class="m-dropdown__menu-item">Text 1</span>
  <span class="m-dropdown__menu-item">Text 2</span>
  <span class="m-dropdown__menu-item">Text 3</span>
  <span class="m-dropdown__menu-item">Text 4</span>
</div>

Radio Buttons

<div class="m-dropdown__menu">
  <div class="m-dropdown__menu-item">
    <input class="a-input" type="radio" name="radios" id="radio1">
    <label for="radio1"></label>
    <label class="-text" for="radio1">Radio Button 1</label>
  </div>
  <div class="m-dropdown__menu-item">
    <input class="a-input" type="radio" name="radios" id="radio2" disabled="">
    <label for="radio2"></label>
    <label class="-text" for="radio2">Disabled Radio Button 2</label>
  </div>
  <div class="m-dropdown__menu-item">
    <input class="a-input" type="radio" name="radios" id="radio3">
    <label for="radio3"></label>
    <label class="-text" for="radio3">Radio Button 3</label>
  </div>
  <div class="m-dropdown__menu-item">
    <input class="a-input" type="radio" name="radios" id="radio4">
    <label for="radio4"></label>
    <label class="-text" for="radio4">Radio Button 4</label>
  </div>
</div>

Text Input

<div class="m-dropdown__menu">
  <a class="m-dropdown__menu-item" href="#">Link 1</a>
  <a class="m-dropdown__menu-item" href="#">Link 2</a>
  <div class="a-divider"></div>
  <div class="m-dropdown__menu-item">
    <input class="a-input" type="text" placeholder="Placeholder">
  </div>
</div>

Range Input

<div class="m-dropdown__menu">
  <div class="m-dropdown__menu-item">
    <label class="-text -mr--2">200GB</label>
    <input class="a-input" type="range">
    <label class="-text -ml--2">5TB</label>
  </div>
  <div class="a-divider"></div>
  <span class="m-dropdown__menu-item">Select range</span>
  <div class="m-dropdown__menu-item">
    <input class="a-input" type="range">
  </div>
</div>

Toggle Switch

<div class="m-dropdown__menu">
  <div class="m-dropdown__menu-item">
    <input class="a-input -toggle" type="checkbox" id="toggle-mail">
    <label class="-mr--1" for="toggle-mail"></label>
    <label class="-text" for="toggle-mail">Email notifications</label>
  </div>
  <div class="m-dropdown__menu-item">
    <input class="a-input -toggle" type="checkbox" id="toggle-tlf">
    <label class="-mr--1" for="toggle-tlf"></label>
    <label class="-text" for="toggle-tlf">Phone notifications</label>
  </div>
  <div class="m-dropdown__menu-item">
    <input class="a-input -toggle" type="checkbox" id="toggle-app">
    <label class="-mr--1" for="toggle-app"></label>
    <label class="-text" for="toggle-app">App notifications</label>
  </div>
</div>

Helpers

Truncate long menu-items

Wrap the menu-item content in a div with the class -flex--ellipsis to truncate long strings.

<div class="m-dropdown__menu" style="width:10rem">
  <a class="m-dropdown__menu-item" href="#">Element 1</a>
  <a class="m-dropdown__menu-item" href="#">Element 2</a>
  <a class="m-dropdown__menu-item" href="#">
    <div class="-flex--ellipsis">Long text element 3</div>
  </a>
  <a class="m-dropdown__menu-item" href="#">Element 4</a>
</div>

Flexible height

Add the class -h--auto to set menu item height to auto.

<div class="m-dropdown__menu" style="width:10rem">
  <a class="m-dropdown__menu-item" href="#">Link 1</a>
  <div class="m-dropdown__menu-item -h--auto -py--1">Lorem ipsum dolor sit amet, consectetur adipisicing elit.</div>
  <a class="m-dropdown__menu-item" href="#">Link 2</a>
</div>

Animation

Triggers can be animated by applying the -animate class.

Example

<div class="m-dropdown">
  <button class="a-btn m-dropdown__trigger -animate">Animated dropdown trigger</button>
  <div class="m-dropdown__menu">
    <a class="m-dropdown__menu-item" href="#">Element 1</a>
    <a class="m-dropdown__menu-item" href="#">Element 2</a>
    <a class="m-dropdown__menu-item" href="#">Element 3</a>
  </div>
</div>
<div class="m-dropdown">
  <button class="a-btn m-dropdown__trigger -animate -active">Animated dropdown trigger</button>
  <div class="m-dropdown__menu -active">
    <a class="m-dropdown__menu-item" href="#">Element 1</a>
    <a class="m-dropdown__menu-item" href="#">Element 2</a>
    <a class="m-dropdown__menu-item" href="#">Element 3</a>
  </div>
</div>

Positioning

Dropdown is prepared to work with positioning libraries like Popper.js. That is why we support the data-position attribute. Chevron orientation will change depending on its value. Valid values are default, initial, top, right, bottom, left, top-start, top-end, right-start, right-end, bottom-start, bottom-end, left-start, left-end.

<div class="m-dropdown">
  <button class="a-btn m-dropdown__trigger" data-position="bottom">Drop-down</button>
  <div class="m-dropdown__menu">
    <a class="m-dropdown__menu-item" href="#">Element 1</a>
    <a class="m-dropdown__menu-item" href="#">Element 2</a>
    <a class="m-dropdown__menu-item" href="#">Element 3</a>
  </div>
</div>