Rate this docs

Angular Bootstrap Dropdowns

Angular dropdowns - Bootstrap 4 & Material Design

Toggle contextual overlays for displaying lists of links and more with the Angular Bootstrap dropdown.


Overview

Dropdowns are toggleable, contextual overlays for displaying lists of links and more. They’re made interactive with the included Bootstrap dropdown JavaScript plugin. They’re toggled by clicking, not by hovering; this is an intentional design decision.

In case of more complicated navigations systems dropdowns are the essential elements providing you with possibility of placing all the most relevant links in our navigation bar (or other component acting as navigation - such as SideNav)

Aside from being not only highly functional, MDB dropdowns are also extraordinary visually attractive. It gives them this characteristic Material Design effects, like shadows, living colors or charming waves effect after opening a link.

They’re toggled by clicking, not by hovering; this is an intentional design decision. Why?

MDB is "mobile first" framework so, we avoid mixing functional elements and interaction by hovering because it decreases User Experience of users of mobile devices.

Google Material Design guidelines recommend the same approach.


Accessibility

The WAI ARIA standard defines an actual role="menu" widget, but this is specific to application-like menus which trigger actions or functions. ARIA menus can only contain menu items, checkbox menu items, radio button menu items, radio button groups, and sub-menus.

Bootstrap’s dropdowns, on the other hand, are designed to be generic and applicable to a variety of situations and markup structures. For instance, it is possible to create dropdowns that contain additional inputs and form controls, such as search fields or login forms. For this reason, Bootstrap does not expect (nor automatically add) any of the role and aria- attributes required for true ARIA menus. Authors will have to include these more specific attributes themselves.

However, Bootstrap does add built-in support for most standard keyboard menu interactions, such as the ability to move through individual .dropdown-item elements using the cursor keys and close the menu with the ESC key.


Examples

Wrap the dropdown’s toggle (your button or link) and the dropdown menu within <button> elements to better fit your potential needs.

Single button



        <div class="btn-group" mdbDropdown>
          <button mdbDropdownToggle type="button" mdbBtn color="primary" class="dropdown-toggle waves-light"
            mdbWavesEffect>
            Basic dropdown
          </button>

          <div class="dropdown-menu dropdown-primary">
            <a class="dropdown-item" href="#">Action</a>
            <a class="dropdown-item" href="#">Another action</a>
            <a class="dropdown-item" href="#">Something else here</a>
            <div class="divider dropdown-divider"></div>
            <a class="dropdown-item" href="#">Separated link</a>
          </div>
        </div>

        <div class="dropdown" mdbDropdown>


          <button mdbDropdownToggle mdbBtn color="primary" class="dropdown-toggle waves-light" type="button"
            mdbWavesEffect>
            Dropdown primary
          </button>


          <div class="dropdown-menu dropdown-primary">
            <a class="dropdown-item" href="#">Action</a>
            <a class="dropdown-item" href="#">Another action</a>
            <a class="dropdown-item" href="#">Something else here</a>
            <a class="dropdown-item" href="#">Something else here</a>
          </div>
        </div>

      

Split button

Similarly, create split button dropdowns with virtually the same markup as single button dropdowns, but with the addition of .dropdown-toggle-split for proper spacing around the dropdown caret.

We use this extra class to reduce the horizontal padding on either side of the caret by 25% and remove the margin-left that’s added for regular button dropdowns. Those extra changes keep the caret centered in the split button and provide a more appropriately sized hit area next to the main button.



        <div class="btn-group" mdbDropdown>
          <button type="button" mdbBtn color="danger" class="waves-light" mdbWavesEffect>Action</button>
          <button type="button" mdbDropdownToggle mdbBtn color="danger" class="dropdown-toggle dropdown-toggle-split px-3 waves-light"
            mdbWavesEffect></button>
          <div class="dropdown-menu">
            <a class="dropdown-item" href="#">Action</a>
            <a class="dropdown-item" href="#">Another action</a>
            <a class="dropdown-item" href="#">Something else here</a>
            <div class="dropdown-divider"></div>
            <a class="dropdown-item" href="#">Separated link</a>
          </div>
        </div>

      

Material dropdowns MDB Pro component


        <div class="dropdown" mdbDropdown>

          <button mdbDropdownToggle mdbBtn color="primary" class="dropdown-toggle waves-light" type="button"
            mdbWavesEffect>
            Dropdown primary
          </button>


          <div class="dropdown-menu dropdown-primary">
            <a class="dropdown-item" href="#">Action</a>
            <a class="dropdown-item" href="#">Another action</a>
            <a class="dropdown-item" href="#">Something else here</a>
            <a class="dropdown-item" href="#">Something else here</a>
          </div>
        </div>
      

Sizing

Button dropdowns work with buttons of all sizes



        <div class="btn-group" mdbDropdown>
          <button mdbDropdownToggle mdbBtn color="danger" size="lg" class="dropdown-toggle waves-light" type="button"
            mdbWavesEffect>
            Large button
          </button>
          <div class="dropdown-menu">
            <a class="dropdown-item" href="#">Action</a>
            <a class="dropdown-item" href="#">Another action</a>
            <a class="dropdown-item" href="#">Something else here</a>
            <div class="dropdown-divider"></div>
            <a class="dropdown-item" href="#">Separated link</a>
          </div>
        </div>

        <div class="btn-group" mdbDropdown>
          <button mdbDropdownToggle mdbBtn color="danger" size="sm" class="dropdown-toggle waves-light" type="button"
            mdbWavesEffect>
            Small button
          </button>
          <div class="dropdown-menu">
            <a class="dropdown-item" href="#">Action</a>
            <a class="dropdown-item" href="#">Another action</a>
            <a class="dropdown-item" href="#">Something else here</a>
            <div class="dropdown-divider"></div>
            <a class="dropdown-item" href="#">Separated link</a>
          </div>
        </div>

      

Dropup variation

Trigger dropdown menus above elements by adding [dropup]="true" to the parent.



        <div class="btn-group" mdbDropdown [dropup]="true">
          <button type="button" mdbBtn color="primary" class="waves-light" mdbWavesEffect>Dropup</button>
          <button type="button" mdbBtn color="primary" mdbDropdownToggle class="dropdown-toggle dropdown-toggle-split px-3 waves-light"
            mdbWavesEffect></button>
          <div class="dropdown-menu">
            <a class="dropdown-item" href="#">Action</a>
            <a class="dropdown-item" href="#">Another action</a>
            <a class="dropdown-item" href="#">Something else here</a>
            <div class="dropdown-divider"></div>
            <a class="dropdown-item" href="#">Separated link</a>
          </div>
        </div>

      





Active menu items

Add .active to items in the dropdown to style them as active.



        <div class="dropdown" mdbDropdown>
          <button mdbDropdownToggle type="button" mdbBtn color="primary" class="dropdown-toggle waves-light"
            mdbWavesEffect>
            Dropdown
          </button>

          <div class="dropdown-menu">
            <a class="dropdown-item" href="#">Action</a>
            <a class="dropdown-item active" href="#">Another action</a>
            <a class="dropdown-item" href="#">Something else here</a>
          </div>
        </div>

      

Disabled menu items

Add .disabled to items in the dropdown to style them as disabled.



        <div class="dropdown" mdbDropdown>
          <button mdbDropdownToggle type="button" mdbBtn color="primary" class="dropdown-toggle waves-light"
            mdbWavesEffect>
            Dropdown
          </button>

          <div class="dropdown-menu">
            <a class="dropdown-item" href="#">Regular link</a>
            <a class="dropdown-item disabled" href="#">Disabled link</a>
            <a class="dropdown-item" href="#">Another link</a>
          </div>
        </div>

      

Angular Dropdown - API

In this section you will find informations about dropdown and its required modules and available inputs, outputs, methods and events.


Modules used

In order to speed up your application, you can choose to import only the modules you actually need, instead of importing the entire MDB Angular library. Remember that importing the entire library, and immediately afterwards a specific module, is bad practice, and can cause application errors.

// MDB Angular Pro
import { ButtonsModule, WavesModule, DropdownModule } from 'ng-uikit-pro-standard'
// MDB Angular Pro
import { ButtonsModule, WavesModule, DropdownModule } from 'angular-bootstrap-md'

Inputs

BsDropdownDirective
Name Type Default Description Example
autoClose boolean false Indicates that dropdown will be closed on item or document click, and after pressing ESC. autoClose="true"
dropup boolean false This attribute indicates that the dropdown should be opened upwards. dropup="true"
isDisabled boolean false Disables dropdown toggle and hides dropdown menu if opened isDisabled="true"
isOpen boolean false Returns whether or not the popover is currently being shown isOpen="true"
placement string ' ' Placement of a popover. Accepts: "top", "bottom", "left", "right". Also .dropdown-menu-right is needed for .dropdown-menu div placement="right"
triggers string ' ' Specifies events that should trigger. Supports a space separated list of event names triggers="mousedown click"

Outputs

Name Type Description Example
isOpenChange EventEmitter<any> Emits an event when isOpen change (isOpenChange)="isOpenChange()"
hidden EventEmitter<any> Emits an event when the popover is hidden (hidden)="onHidden()"
shown EventEmitter<any> Emits an event when the popover is shown (shown)="onShown()"

Methods

To your mdbDropdown element add #dropdown='bs-dropdown'. And to the trigger add below mentioned options.

Name Description Example
show Opens an element’s popover. This is considered a “manual” triggering of the popover (event)="name.show()"
hide Closes an element’s popover. This is considered a “manual” triggering of the popover (event)="name.hide()"
toggle Toggles an element’s popover. This is considered a “manual” triggering of the popover (event)="name.toggle(value: boolean)()"