Dropdown

How it works

Use Bootstrap's custom button styles for actions in forms, dialogs, and more with support for multiple sizes, states, and more. There is three types of tags that can be used for create a button: button, a and input.

Basic example

<x-dropdown id="BasicDemo">
    <x-dropdown.toggle>Toggle dropdown</x-dropdown.toggle>
    <x-dropdown.menu>
        <x-dropdown.item href="/docs/components/introduction">Link one</x-dropdown.item>
        <x-dropdown.item href="/docs/components/accordion">Link two</x-dropdown.item>
        <x-dropdown.divider/>
        <x-dropdown.item href="/docs/components/dropdown" aria-current="true" active>Link three</x-dropdown.item>
    </x-dropdown.menu>
</x-dropdown>
<div class="dropdown">
  <button id="dropdownMenuBasicDemo"
       data-bs-toggle="dropdown"
       aria-expanded="false"
       data-bs-reference="toggle"
       class="dropdown-toggle btn btn-primary">Toggle dropdown</button>
  <div class="dropdown-menu"
       aria-labelledby="dropdownMenuBasicDemo">
    <a class="dropdown-item"
         href="/docs/components/introduction">Link one</a> <a class="dropdown-item"
         href="/docs/components/accordion">Link two</a>
    <div class="dropdown-divider">
    </div>
    <a class="dropdown-item active"
         href="/docs/components/dropdown"
         aria-current="true"
         active="active">Link three</a>
  </div>
</div>

List example

By default the dropdown items are link wrapped inside a div tag. If you want to use instead use a ul, then pass prop list. Simple as that?

<x-dropdown id="ListDemo" list>
    <x-dropdown.toggle>Toggle dropdown list</x-dropdown.toggle>
    <x-dropdown.menu>
        <x-dropdown.item href="/docs/components/introduction">Link one</x-dropdown.item>
        <x-dropdown.item href="/docs/components/accordion">Link two</x-dropdown.item>
        <x-dropdown.divider/>
        <x-dropdown.item href="/docs/components/dropdown" aria-current="true" active>Link three</x-dropdown.item>
    </x-dropdown.menu>
</x-dropdown>
<div class="dropdown">
  <button id="dropdownMenuListDemo"
       data-bs-toggle="dropdown"
       aria-expanded="false"
       data-bs-reference="toggle"
       class="dropdown-toggle btn btn-primary">Toggle dropdown list</button>
  <div class="dropdown-menu"
       aria-labelledby="dropdownMenuListDemo">
    <ul>
      <li>
        <a class="dropdown-item"
            href="/docs/components/introduction">Link one</a>
      </li>

      <li>
        <a class="dropdown-item"
            href="/docs/components/accordion">Link two</a>
      </li>

      <li style="list-style: none; display: inline">
        <div class="dropdown-divider">
        </div>
      </li>

      <li>
        <a class="dropdown-item active"
            href="/docs/components/dropdown"
            aria-current="true"
            active="active">Link three</a>
      </li>
    </ul>
  </div>
</div>

Using different dropdown toggle

Bootstrap has three type of dropdown toggle: button, link or button split. Use component x-dropdown.toggle.a or x-dropdown.toggle.split for toggle dropdown with a link or button split. By default, it's a button. You can use directly the component x-dropdown.toggle.button, x-dropdown.toggle.a and x-dropdown.toggle.split Or you just pass prop type to x-dropdown.toggle.

<x-dropdown id="ToggleDemo">
    <x-dropdown.toggle.a>Toggle dropdown link</x-dropdown.toggle.a>
    <x-dropdown.menu>
        <x-dropdown.item href="/docs/components/introduction">Link one</x-dropdown.item>
        <x-dropdown.item href="/docs/components/accordion">Link two</x-dropdown.item>
        <x-dropdown.divider/>
        <x-dropdown.item href="/docs/components/dropdown" aria-current="true" active>Link three</x-dropdown.item>
    </x-dropdown.menu>
</x-dropdown>

<x-dropdown id="ToggleDemo2" split>
    <x-dropdown.toggle>Toggle dropdown split</x-dropdown.toggle>
    <x-dropdown.menu>
        <x-dropdown.item href="/docs/components/introduction">Link one</x-dropdown.item>
        <x-dropdown.item href="/docs/components/accordion">Link two</x-dropdown.item>
        <x-dropdown.divider/>
        <x-dropdown.item href="/docs/components/dropdown" aria-current="true" active>Link three</x-dropdown.item>
    </x-dropdown.menu>
</x-dropdown>
<div class="dropdown">
  <a href="#"
       id="dropdownMenuToggleDemo"
       data-bs-toggle="dropdown"
       role="button"
       aria-expanded="false"
       class="dropdown-toggle"
       name="dropdownMenuToggleDemo">Toggle dropdown link</a>
  <div class="dropdown-menu"
       aria-labelledby="dropdownMenuToggleDemo">
    <a class="dropdown-item"
         href="/docs/components/introduction">Link one</a> <a class="dropdown-item"
         href="/docs/components/accordion">Link two</a>
    <div class="dropdown-divider">
    </div>
    <a class="dropdown-item active"
         href="/docs/components/dropdown"
         aria-current="true"
         active="active">Link three</a>
  </div>
</div>
<br>
<br>

<div class="dropdown btn-group">
  <button type="button"
       class="btn btn-primary">Toggle dropdown split</button> <button id="dropdownMenuToggleDemo2"
       data-bs-toggle="dropdown"
       aria-expanded="false"
       data-bs-reference="toggle"
       class="dropdown-toggle dropdown-toggle-split btn btn-primary"><span class="visually-hidden">Toggle Dropdown</span></button>
  <div class="dropdown-menu"
       aria-labelledby="dropdownMenuToggleDemo2">
    <a class="dropdown-item"
         href="/docs/components/introduction">Link one</a> <a class="dropdown-item"
         href="/docs/components/accordion">Link two</a>
    <div class="dropdown-divider">
    </div>
    <a class="dropdown-item active"
         href="/docs/components/dropdown"
         aria-current="true"
         active="active">Link three</a>
  </div>
</div>

Dropdown as list using component

You can also use component x-dropdown.menu.ul for create a dropdown as list.

Dropdown size

You can use prop size to change size of dropdown.

Dropdown dark

You can use prop dark to make your dropdown dark.

Dropdown positions

You can use prop position to change the position of the dropdown.

Dropdown using slot

If you want to use slots instead of child components, then find below an example.

Dropstart with split button

Dropstart with split button require a different markup than others, so if you need such case, you can find below an example. See bootstrap docs about such markup.

<x-button.group>
    <x-dropdown id="DropstartSplitDemo" start group>
        <x-button toggle="dropdown" aria-expanded="false" class="dropdown-toggle dropdown-toggle-split">
            <span class="visually-hidden">Toggle Dropstart</span>
        </x-button>
        <x-dropdown.menu>
            <x-dropdown.item href="/docs/components/introduction">Link one</x-dropdown.item>
            <x-dropdown.item href="/docs/components/accordion">Link two</x-dropdown.item>
            <x-dropdown.divider/>
            <x-dropdown.item href="/docs/components/dropdown" active>Link three</x-dropdown.item>
        </x-dropdown.menu>
    </x-dropdown>
    <x-button>Split dropstart</x-button>
</x-button.group>
<div role="group"
     aria-label="Button group"
     class="btn-group">
  <div role="group"
       class="dropdown dropstart btn-group">
    <button type="button"
         data-bs-toggle="dropdown"
         aria-expanded="false"
         class="btn btn-primary dropdown-toggle dropdown-toggle-split"><span class="visually-hidden">Toggle Dropstart</span></button>
    <div class="dropdown-menu dropdown-menu-start"
         aria-labelledby="dropdownMenuDropstartSplitDemo"
         data-bs-display="static">
      <a class="dropdown-item"
           href="/docs/components/introduction">Link one</a> <a class="dropdown-item"
           href="/docs/components/accordion">Link two</a>
      <div class="dropdown-divider">
      </div>
      <a class="dropdown-item active"
           href="/docs/components/dropdown"
           active="active">Link three</a>
    </div>
  </div>
  <button type="button"
       class="btn btn-primary">Split dropstart</button>
</div>