Skip to content

Dropdown ​

A menu of actions built on the Bootstrap Dropdown plugin, with labels, shortcuts and a destructive item.

  • Version 1.1.0
  • Bootstrap 5.3+
  • Requires Bootstrap CSS + Bootstrap JS bundle
  • Source on GitHub

Installation ​

bash
npx bootcn add dropdown
bash
pnpm dlx bootcn add dropdown
bash
yarn dlx bootcn add dropdown
bash
bunx --bun bootcn add dropdown

The CLI also installs the design tokens and these components: button. It prints the <link> and <script> tags to add to your layout.

Usage ​

html
<div class="dropdown bootcn-dropdown">
  <button
    class="btn bootcn-button bootcn-button--outline dropdown-toggle"
    type="button"
    id="account-menu"
    data-bs-toggle="dropdown"
    aria-expanded="false"
  >
    My account
  </button>
  <ul class="dropdown-menu bootcn-dropdown__menu" aria-labelledby="account-menu">
    <li>
      <span class="dropdown-header bootcn-dropdown__label">Signed in as maria@example.com</span>
    </li>
    <li><a class="dropdown-item bootcn-dropdown__item" href="/profile">Profile</a></li>
    <li><hr class="dropdown-divider bootcn-dropdown__divider" /></li>
    <li>
      <button
        class="dropdown-item bootcn-dropdown__item bootcn-dropdown__item--destructive"
        type="button"
      >
        Sign out
      </button>
    </li>
  </ul>
</div>

Use links for navigation and buttons for actions. Disabled actions use the disabled attribute on a <button>.

Parts ​

  • bootcn-dropdown__label — non-interactive section label.
  • bootcn-dropdown__shortcut — right-aligned keyboard hint (decorative; mark it aria-hidden="true" and implement the shortcut yourself).
  • bootcn-dropdown__item--destructive — danger-colored item.

Dependencies ​

  • Bootstrap 5.3+ CSS and JavaScript bundle (Dropdown + Popper).
  • themes/tokens/tokens.css, button (trigger styling).

Accessibility ​

  • The trigger has aria-expanded, updated by Bootstrap; the menu is labelled by the trigger.
  • Arrow keys move through items, Escape closes the menu and returns focus to the trigger.
  • Bootstrap's dropdown is a disclosure list of links and buttons, not an ARIA menu; this matches how most screen-reader users expect site navigation to behave.

Source ​

The exact files the CLI installs (dropdown@1.1.0). View on GitHub · Report an issue

html
<div class="dropdown bootcn-dropdown">
  <button
    class="btn bootcn-button bootcn-button--outline dropdown-toggle"
    type="button"
    id="bootcn-dropdown-trigger"
    data-bs-toggle="dropdown"
    aria-expanded="false"
  >
    My account
  </button>
  <ul class="dropdown-menu bootcn-dropdown__menu" aria-labelledby="bootcn-dropdown-trigger">
    <li>
      <span class="dropdown-header bootcn-dropdown__label">Signed in as maria@example.com</span>
    </li>
    <li>
      <a class="dropdown-item bootcn-dropdown__item" href="#profile">
        Profile <span class="bootcn-dropdown__shortcut" aria-hidden="true">⌘P</span>
      </a>
    </li>
    <li>
      <a class="dropdown-item bootcn-dropdown__item" href="#settings">
        Settings <span class="bootcn-dropdown__shortcut" aria-hidden="true">⌘,</span>
      </a>
    </li>
    <li>
      <button class="dropdown-item bootcn-dropdown__item" type="button" disabled>
        Billing (soon)
      </button>
    </li>
    <li><hr class="dropdown-divider bootcn-dropdown__divider" /></li>
    <li>
      <button
        class="dropdown-item bootcn-dropdown__item bootcn-dropdown__item--destructive"
        type="button"
      >
        Sign out
      </button>
    </li>
  </ul>
</div>
css
.bootcn-dropdown__menu {
  --bs-dropdown-min-width: 14rem;
  --bs-dropdown-padding-x: 0.25rem;
  --bs-dropdown-padding-y: 0.25rem;
  --bs-dropdown-border-color: var(--bootcn-border-color);
  --bs-dropdown-border-radius: var(--bootcn-radius);
  --bs-dropdown-bg: var(--bootcn-background);
  --bs-dropdown-color: var(--bootcn-foreground);
  --bs-dropdown-link-color: var(--bootcn-foreground);
  --bs-dropdown-link-hover-color: var(--bootcn-accent-foreground);
  --bs-dropdown-header-color: var(--bootcn-muted-foreground);
  --bs-dropdown-item-padding-x: 0.5rem;
  --bs-dropdown-item-padding-y: 0.375rem;
  --bs-dropdown-item-border-radius: var(--bootcn-radius-sm);
  --bs-dropdown-link-hover-bg: var(--bootcn-accent);
  --bs-dropdown-link-active-bg: var(--bootcn-accent);
  --bs-dropdown-link-active-color: var(--bootcn-accent-foreground);
  --bs-dropdown-header-padding-x: 0.5rem;
  --bs-dropdown-header-padding-y: 0.375rem;
  --bs-dropdown-divider-margin-y: 0.25rem;
  --bs-dropdown-font-size: 0.875rem;

  box-shadow: var(--bootcn-shadow-md);
}

.bootcn-dropdown__item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border-radius: var(--bs-dropdown-item-border-radius);
}

.bootcn-dropdown__item:focus-visible {
  outline: 0;
  background-color: var(--bootcn-accent);
  box-shadow: inset 0 0 0 2px var(--bootcn-focus-ring-color);
}

.bootcn-dropdown__item--destructive,
.bootcn-dropdown__item--destructive:hover,
.bootcn-dropdown__item--destructive:focus {
  color: var(--bs-danger-text-emphasis);
}

.bootcn-dropdown__label {
  color: var(--bs-secondary-color);
  font-size: 0.8125rem;
  font-weight: 500;
}

.bootcn-dropdown__shortcut {
  margin-left: auto;
  color: var(--bs-secondary-color);
  font-size: 0.75rem;
  letter-spacing: 0.05em;
}

.bootcn-dropdown__divider {
  border-color: var(--bootcn-border-color);
  opacity: 1;
}

Released under the MIT License. Not affiliated with Bootstrap or shadcn/ui.