# Dropdown

Source: https://iriscss.com/documentation/components/dropdown/

A popover list of links or choices, opened by a button. No JavaScript.

```html
<button popovertarget="dropdown-account">Account</button>
<ul id="dropdown-account" popover class="dropdown">
  <li><a href="#">Profile</a></li>
  <li><a href="#" aria-current="page">Settings</a></li>
  <li><a href="#">Sign out</a></li>
</ul>
```

Give the list `popover` and `.dropdown`, and point the button's `popovertarget` at its `id`. Put the list right after the button, which then shows a chevron that turns while the menu is open. Clicking outside or pressing `Esc` closes it, and the browser tells screen readers whether it is open. `aria-current` marks the selected link.

Where the browser supports anchor positioning, the menu opens below the button, at least as wide as it, and flips above it near the bottom of the screen. It sits in the top layer, so no container clips it. Browsers without anchor positioning center it like any [popover](https://iriscss.com/documentation/elements/popover/index.html.md).

## Button

The button keeps every [button](https://iriscss.com/documentation/elements/button/index.html.md) color, style and size.

```html
<button popovertarget="dropdown-actions" class="primary">Actions</button>
<ul id="dropdown-actions" popover class="dropdown">
  <li><a href="#">Duplicate</a></li>
  <li><a href="#">Archive</a></li>
</ul>
<button popovertarget="dropdown-more" class="secondary outlined small">More</button>
<ul id="dropdown-more" popover class="dropdown">
  <li><a href="#">Export</a></li>
  <li><a href="#">Print</a></li>
</ul>
```

## Select

`.select` draws the button as a [select](https://iriscss.com/documentation/form/controls/index.html.md), for a menu of choices. List items can hold labels with checkboxes or radios.

```html
<button popovertarget="dropdown-languages" class="select">Languages</button>
<ul id="dropdown-languages" popover class="dropdown">
  <li><label><input type="checkbox" name="lang" checked> English</label></li>
  <li><label><input type="checkbox" name="lang"> French</label></li>
  <li><label><input type="checkbox" name="lang"> German</label></li>
</ul>
```

## In a form

Inside a `label` the select button sits under the label text like any control. `aria-invalid` on it shows a [validation](https://iriscss.com/documentation/form/validation/index.html.md) state.

```html
<label>
  Size
  <button popovertarget="dropdown-size" class="select" aria-invalid="true">Choose a size</button>
</label>
<ul id="dropdown-size" popover class="dropdown">
  <li><label><input type="radio" name="size"> Small</label></li>
  <li><label><input type="radio" name="size"> Large</label></li>
</ul>
```

## In a nav

Inside `nav` a button without a class looks like a link. See [nav](https://iriscss.com/documentation/components/nav/index.html.md).

```html
<nav aria-label="Dropdown example">
  <ul>
    <li><a href="#">Home</a></li>
    <li>
      <button popovertarget="dropdown-products">Products</button>
      <ul id="dropdown-products" popover class="dropdown">
        <li><a href="#">Iris CSS</a></li>
        <li><a href="#">Themes</a></li>
      </ul>
    </li>
  </ul>
</nav>
```

## Sizes and styles

A select button takes size classes, `.rounded`, `.square` and `.outlined`.

```html
<button popovertarget="dropdown-small" class="select small rounded">Small and rounded</button>
<ul id="dropdown-small" popover class="dropdown"><li><a href="#">Item</a></li></ul>
<button popovertarget="dropdown-large" class="select large outlined">Large and outlined</button>
<ul id="dropdown-large" popover class="dropdown"><li><a href="#">Item</a></li></ul>
```

## Variables

| Variable | Default | Note |
| --- | --- | --- |
| `--i-dropdown-offset` | `0.0625rem` | Gap between the button and the menu |
| `--i-dropdown-color-text` | `var(--i-color-text)` |  |
| `--i-dropdown-color-background` | `light-dark(var(--i-color-white), #181c25)` |  |
| `--i-dropdown-color-border` | `light-dark(#eff1f4, #202632)` |  |
| `--i-dropdown-hover-color-background` | `light-dark(#eff1f4, #202632)` |  |
| `--i-dropdown-shadow` | `var(--i-shadow)` |  |
