Dropdown

Dropdowns are toggleable, contextual overlays for displaying lists of links and actions in a dropdown menu format.

BDropdown components are toggleable, contextual overlays for displaying lists of links, and more. They're toggled by clicking (or pressing space or enter when focused), not by hovering; this is an intentional design decision.

Button content

You can customize the text of the dropdown button by using either the text prop (shown in previous examples), or use the button-content slot instead of the text prop. The button-content slot allows you to use basic HTML and icons in the button content.

If both the prop text and slot button-content are present, the slot button-content will take precedence.

Positioning

Dropdown supports various positioning such as left (start) and right (end) aligned, dropdown and dropup, and supports auto-flipping dropdown to dropup, and vice-versa) when the menu would overflow off of the visible screen area.

The dropdown menu can either be start aligned (default) or end aligned to the button above it. To have the dropdown aligned on the end, set the end prop.

Dropup

Turn your dropdown menu into a drop-up menu by setting the placement prop.

Drop placement

Turn your dropdown menu into a drop left, right or other menu by setting the placement prop.

Values for placement come from floating-ui's placement definition.

Auto "flipping"

By default, dropdowns may flip to the top, or the bottom, based on their current position in the viewport. To disable this auto-flip feature, set the no-flip prop.

Like to move your menu away from the toggle buttons a bit? Then use the offset prop to specify the number of pixels to push right (or left when negative) from the toggle button:

Floating Strategy

By default, the floating element will render using absolute. You can change this using the strategy prop. The only other option is fixed. See the floating-ui documentation for details.

Boundary constraint

By default, dropdowns are visually constrained to their clipping ancestors, which will suffice in most situations. However, if you place a dropdown inside an element that has overflow: scroll (or similar) set, the dropdown menu may - in some situations - get cut off. To get around this, you can specify a boundary element via the boundary prop. Supported values any values from floating-uiBoundary or RootBoundary types. The default value is clippingAncestors.

Note: When boundary is any value other than the default of clippingAncestors, the style position: static is applied to the dropdown component's root element to allow the menu to "break out" of its scroll container. In some situations, this may affect your layout or positioning of the dropdown trigger button. In these cases, you may need to wrap your dropdown inside another element

Note: BootstrapVueNext uses floating-ui under the hood, so please read their options documnetation for details on boundary and boundary-padding.

Container element

By default, dropdowns are next to the toggle button. However, you can specify a container element via the container prop where dropdowns will be teleported to instead. Supported values are CSS selector string, an actual DOM node or a reference to an HTML element.

By default, the dropdown menu is closed when clicking inside or outside the dropdown menu. You can use the auto-close property to change this behavior of the dropdown.

The auto-closeproperty has 4 options.

  • true : the dropdown will be closed by clicking outside or inside the dropdown menu
  • false : the dropdown will be closed by clicking the toggle button and manually calling the hide method. (Also will not be closed by pressing esc key)
  • inside : the dropdown will be closed (only) by clicking inside the dropdown menu
  • outside : the dropdown will be closed (only) by clicking outside the dropdown menu

Advanced floating-ui configuration

Occasionally you may want to modify the floating-ui behavior. We already expose some configurations through the no-flip, no-shift, strategy, and offset props. However, lower-level access to the API may sometimes be required. You can use the floatingMiddleware prop to define middleware to pass through to the floating-ui element.

You can view the Floating-ui docs to learn more about their middleware. Note: You will likely want to install @floating-ui/vue to use their middleware directly, rather than rebuilding middleware options.

Note: Using the floatingMiddleware prop will overwrite other defined middleware such as offset, noFlip, and noShift. They are not merged.

Split button support

Create a split dropdown button, where the left button provides a split-click event and link support, while the right-hand side is the dropdown menu toggle button.

The left split button defaults to an element of type <button> (a BButton to be exact). To convert this button into a link or RouterLink, specify the href via the split-href prop or a router link to value via the split-to prop, while maintaining the look of a button.

Split button type

The split button defaults to a button type of button. You can specify an alternate type via the split-button-type prop. Supported values are: button, submit, and reset.

If props split-to or split-href are set, the split-button-type prop will be ignored.

Styling options

Dropdowns support various props for styling the dropdown trigger button.

Sizing

Dropdowns work with trigger buttons of all sizes, including default and split dropdown buttons.

Set the size prop to either sm for a small button, or lg for a large button.

Note: changing the size of the button(s) does not affect the size of the menu items!

The dropdown toggle button can have one of the standard Bootstrap contextual variants applied by setting the prop variant to success, primary, info, danger, link, outline-dark, etc. (or custom variants, if defined). The default variant is secondary.

See the Variant Reference for a full list of built-in contextual variants.

You can also apply arbitrary classes to the toggle button via the toggle-class prop.

Split button color variant

By default, the left split button uses the same variant as the toggle button. You can give the split button its variant via the split-variant prop.

Dark mode

Dark variants for components were deprecated in Bootstrap v5.3.0. See their documentation for details.

Block level dropdowns

By default, dropdowns act like buttons and are displayed inline. Create a full-width, “block button” by adding the classes d-grid and gap-2 to the BDropdown. For split buttons, wrap the BDropdown in a div that has the d-grid and gap-2 classes and add split-class="w-100" to the BDropdown itself. See the Bootstrap 5 button documentation for details

If you want the dropdown menu to span to the full width of the parent container too, add the w-100 utility class to the menu-class prop.

Many of the supported dropdown sub-components provide a variant prop for controlling their text color.

Hidden caret

The dropdown can be created with the toggle's caret visually hidden by setting the no-caret prop to true. This is useful when the dropdown is to be displayed as an icon.

Note: The caret will always be shown when using split mode.

v-model support

The dropdown's opened state is bound to the component's v-model. Programatic control of the state of the dropdown can be managed via the model. The model can also be used to observe the state of the dropdown.

Exposed Methods

You are also able to use the built in methods for showing, hiding or toggling the dropdown viatemplate refs.

  1. show: shows the dropdown
  2. hide: hides the dropdown
  3. toggle: toggles the dropdown

The following components can be placed inside your dropdowns. Using any other component or markup may break layout and/or keyboard navigation.

Sub-componentDescription
BDropdownItemAction items that provide click, link, and RouterLink/NuxtLink functionality. Renders as an <a> element by default
BDropdownItemButtonAn alternative to BDropdownItem that renders a menu item using a <button> element
BDropdownDividerA divider/spacer which can be used to separate dropdown items
BDropdownTextFree flowing text content in a menu
BDropdownGroupFor grouping dropdown sub-components with an optional header
BDropdownHeaderA header item, used to help identify a group of dropdown items
BDropdownFormFor placing form controls within a dropdown menu.

WARNING

Nested sub-menus are not supported.

TIP

There are small differences in how the sub-components behave, please read our migration guide if you are converting from bootstrap-vue.

BDropdownItem

The BDropdownItem is typically used to create a navigation link inside your menu. Use either the href prop or the to prop (for router link support) to generate the appropriate navigation link. If neither href nor to are provided, a standard <a> link will be generated with an href of # (with an event handler that will prevent scroll to top behavior by preventing the default link action).

Disabled the dropdown item by setting the disabled prop.

BDropdownItemButton

Historically dropdown menu contents had to be links (BDropdownItem), but that is no longer the case with Bootstrap v5. Now you can optionally create <button> elements in your dropdowns by using the BDropdownItemButton sub-component. BDropdownItemButton does not support the href or to props.

Disabled the dropdown item button by setting the disabled prop.

When the menu item does not trigger navigation, it is recommended to use the BDropdownItemButton sub-component.

BDropdownDivider

Separate groups of related menu items with BDropdownDivider.

BDropdownText

Place any freeform text within a dropdown menu using the BDropdownText sub-component or use text combined with spacing utilities. Note that you'll likely need additional sizing styles to constrain/set the menu width.

BDropdownText has the BootstrapVueNext custom class .b-dropdown-text applied to it which sets some basic styles which are suitable in most situations. By default, its width will be the same as the widest BDropdownItem content. You may need to place additional styles or helper classes on the component.

variant)

BDropdownGroup

Group a set of dropdown sub-components with an optional associated header. Place a BDropdownDivider between your BDropdownGroup and other groups or non-grouped dropdown contents.

BDropdownHeader

Add a header to label sections of actions in any dropdown menu.

See Section Headers and accessibility for details on making headers more accessible for users of assistive technologies.

Using the BDropdownGroup sub-component simplifies creating accessible grouped dropdown items with an associated header.

BDropdownForm

Add a form into your dropdown with BDropdownForm.

Or make it inline.

Accessibility

Providing a unique id prop ensures ARIA compliance by automatically adding the appropriate aria-* attributes in the rendered markup. By default, the dropdown will render a unique id for every dropdown. However, this can be overwritten with the prop id.

The default ARIA role is set to menu, but you can change this default to another role (such as navigation) via the role prop, depending on your use case.

When a menu item does not trigger navigation, it is recommended to use the BDropdownItemButton sub-component (which is not announced as a link) instead of BDropdownItem (which is presented as a link to the user).

Headers and accessibility

When using BDropdownHeader components in the dropdown menu, it is recommended to add an id attribute to each of the headers, and then set the aria-describedby attribute (set to the id value of the associated header) on each following dropdown items under that header. This will provide users of assistive technologies (i.e. sight-impaired users) additional context about the dropdown item:

As a simplified alternative, use the BDropdownGroup instead to easily associate header text to the contained dropdown sub-components.

Keyboard navigation

Dropdowns support keyboard navigation, emulating native <select> behavior.

Note that Down and Up will not move focus into BDropdownForm sub-components, but users can still use Tab or Shift+Tab to move into form controls within the menu.

Lazy

Dropdown menus can have their inner content rendered lazily through the lazy prop. By default, this is turned off. For navigation elements, it may be beneficial to keep lazy off, so web crawlers can properly comb through your sites navigation.

Implementation notes

The dropdown menu is rendered with semantic <ul> and <li> elements for accessibility reasons. The .dropdown-menu is the <ul> element, while dropdown items (items, buttons, text, form, headers, and dividers) are wrapped in an <li> element. If creating custom items to place inside the dropdown menu, ensure they are wrapped with a plain <li>.

See also

Component Reference

<BDropdown>

PropTypeDefaultDescription
aria-labelstringundefined Sets the value of `aria-label` attribute on the rendered element
auto-closeboolean | 'inside' | 'outside'true Controls the automatic closing of the dropdown when clicking. See above for details.
boundaryBoundary | RootBoundary'clippingAncestors' The boundary constraint of dropdown: any value of floating-us's Boundary or RootBoundary type. See above for details.
boundary-paddingPaddingundefined The virtual padding around the boundary to check for overflow
disabledbooleanfalse When set to `true`, disables the component's functionality and places it in a disabled state
floating-middlewareMiddleware[]undefined Directly set the floating-ui middleware behavior. See above for details.
iconbooleanfalse When set, styles an icon at the beginning or end of the button text
idstringundefined Used to set the `id` attribute on the rendered content, and used as the base to generate any additional element IDs as needed
initial-animationbooleanfalse When set, enables the initial animation on mount
is-navbooleanfalse Indicates the dropdown is a nav dropdown
lazybooleanfalse When set, the content will not be mounted until opened
menu-classClassValueundefined CSS class (or classes) to add to the menu container
model-valuebooleanfalse Controls the visibility of the component
no-animationbooleanfalse When set, disables the animation
no-caretbooleanfalse Hide the caret indicator on the toggle button
no-fadebooleanfalse Alias for `noAnimation`
no-flipbooleanfalse Prevent the menu from auto flipping positions
no-shiftbooleanfalse Prevent the menu from automatically shifting positions
no-sizebooleanfalse Prevent the menu from automatically resizing
no-wrapperbooleanfalse Do not render the dropdown wrapper element
offsetnumber | string | {mainAxis?: number; crossAxis?: number; alignmentAxis?: number | null0 Specify the number of pixels to shift the menu by. See above for details.
placementPlacement'bottom-start' Placement of a floating element
rolestring'menu' Sets the ARIA attribute `role` to a specific value
showbooleanfalse When set, and prop 'visible' is false on mount, will animate from closed to open on initial mount. Mainly to help with template show. Use model-value for reactive show/hide
sizeSize'md' Set the size of the component's appearance. 'sm', 'md' (default), or 'lg'
splitbooleanfalse When set, renders a split button dropdown
split-button-typeButtonType'button' Value to place in the 'type' attribute on the split button: 'button', 'submit', 'reset'
split-classClassValueundefined CSS class (or classes) to add to the split button
split-disabledbooleanundefined When set, the split button is disabled
split-hrefstringundefined Denotes the target URL of the link for the split button
split-toRouteLocationRawundefined Denotes the target route of the split button. When clicked, the value of the to prop will be passed to router.push() internally, so the value can be either a string or a Location descriptor object
split-variantButtonVariant | nullundefined Applies one of the Bootstrap theme color variants to the split button. Defaults to the 'variant' prop value
strategyStrategy'absolute' The strategy used to determine when to hide the dropdown. See above for details.
teleport-disabledbooleanfalse Renders the dropdown in the exact place it was defined
teleport-tostring | RendererElement | null | undefinedundefined Overrides the default teleport location
textstringundefined Text to place in the toggle button, or in the split button is split mode
toggle-classClassValueundefined CSS class (or classes) to add to the toggle button
toggle-textstring'Toggle dropdown' ARIA label (visually-hidden) to set on the toggle when in split mode. Overriden by the slot of the same name
trans-propsTransitionPropsundefined Transition properties
unmount-lazybooleanfalse When set and `lazy` is true, the content will be unmounted when closed
variantColorVariant | null'secondary' Applies one of the Bootstrap theme color variants to the component. When implemented `bg-variant` and `text-variant` will take precedence
visiblebooleanfalse When 'true', open without animation
wrapper-classClassValueundefined CSS class (or classes) to add to the wrapper element
EventArgsDescription
cancel
value: BvTriggerableEvent
Emitted when a cancel action is triggered.
hidden
value: BvTriggerableEvent
Always emits after the component is hidden
hide
value: BvTriggerableEvent - Call value.preventDefault() to cancel hide
Always emits just before the component has hidden. Cancelable (as long as component wasn't forcibly hidden)
hide-prevented
value: BvTriggerableEvent
Emitted when the component tried to close, but was prevented from closing. This occurs when preventDefault() is called on the event, the user clicks escape and no-close-onbackdrop is set to true, or the user clicks on the backdrop and no-close-onbackdrop is set to true.
ok
value: BvTriggerableEvent
Emitted when an ok action is triggered.
show
value: BvTriggerableEvent - Call value.preventDefault() to cancel show
Always emits just before the component is shown. Cancelable
show-prevented
value: BvTriggerableEvent
Emitted when the component tried to open, but was prevented from opening. This occurs when preventDefault() is called on the event
shown
value: BvTriggerableEvent
Always emits just after component is shown.
split-click
event: MouseEvent - Native click event object
Emitted when split button is clicked in split mode
toggleEmitted when toggle button is clicked
toggle-prevented
value: BvTriggerableEvent
Emitted when the component tried to toggle, but was prevented from doing so. This occurs when preventDefault() is called on the event, the user clicks escape and no-close-onbackdrop is set to true, or the user clicks on the backdrop and no-close-onbackdrop is set to true.
NameScopeDescription
button-contentCan be used to implement custom text with icons and more styling
default
hide: () => void - Can be used to close the dropdown
show: () => void - Can be used to open the dropdown
Optionally scoped default slot for dropdown menu content
toggle-textARIA label (visually-hidden) to set on the toggle when in split mode. Overrides the toggle-text prop

<BDropdownDivider>

PropTypeDefaultDescription
divider-classClassValueundefined CSS class (or classes) to add to the divider component
tagstring'hr' Specify the HTML tag to render instead of the default tag
variantColorVariant | nullnull Applies one of the Bootstrap theme color variants to the component. When implemented `bg-variant` and `text-variant` will take precedence
wrapper-attrsReadonly<AttrsValue>undefined Attributes to be applied to the wrapper element

<BDropdownForm>

PropTypeDefaultDescription
form-classClassValueundefined CSS class (or classes) to add to the form component
novalidateundefinedNot yet implemented
validatedundefinedNot yet implemented
wrapper-attrsReadonly<AttrsValue>undefined Attributes to be applied to the wrapper element
NameScopeDescription
defaultContent to place in the dropdown form

<BDropdownGroup>

PropTypeDefaultDescription
aria-describedbystringundefined The ID of the element that provides a description for this component. Used as the value for the `aria-describedby` attribute
headerstringundefined
header-classClassValueundefined CSS class (or classes) to apply to the header
header-tagstring'header' Specify the HTML tag to render instead of the default tag for the header
header-variantColorVariant | nullundefined Applies one of the Bootstrap theme color variants to the header
idstringundefined Used to set the `id` attribute on the rendered content, and used as the base to generate any additional element IDs as needed
NameScopeDescription
defaultContent (items) to place in the dropdown group
headerOptional header content for the dropdown group

<BDropdownHeader>

PropTypeDefaultDescription
header-classClassValueundefined CSS class (or classes) to apply to the header
tagstring'div' Specify the HTML tag to render instead of the default tag
textstringundefined Content to place in the dropdown header. Default slot takes precedence
variantColorVariant | nullnull Applies one of the Bootstrap theme color variants to the component. When implemented `bg-variant` and `text-variant` will take precedence
wrapper-attrsReadonly<AttrsValue>undefined Attributes to be applied to the wrapper element
NameScopeDescription
defaultContent to place in the dropdown header

<BDropdownItem>

PropTypeDefaultDescription
link-classClassValueundefined Class or classes to apply to the inner link element
wrapper-attrsReadonly<AttrsValue>undefined Attributes to be applied to the wrapper element
Extensions:
EventArgsDescription
click
value: MouseEvent - Native click event object
Emitted when item is clicked
NameScopeDescription
defaultContent to place in the dropdown item

<BDropdownItemButton>

PropTypeDefaultDescription
activebooleanfalse When set to `true`, places the component in the active state with active styling
active-classClassValue'active' Configure the active CSS class applied when the link is active. Typically you will want to set this to class name 'active'
button-classClassValueundefined Class or classes to apply to the inner button element
disabledbooleanfalse When set to `true`, disables the component's functionality and places it in a disabled state
variantColorVariant | nullnull Applies one of the Bootstrap theme color variants to the component. When implemented `bg-variant` and `text-variant` will take precedence
wrapper-attrsReadonly<AttrsValue>undefined Attributes to be applied to the wrapper element
EventArgsDescription
click
value: MouseEvent - Native click event object
Emitted when item is clicked
NameScopeDescription
defaultContent to place in the dropdown item button

<BDropdownText>

PropTypeDefaultDescription
tagstring'span' Specify the HTML tag to render instead of the default tag
textstringundefined Content to place in the dropdown text. Default slot takes precedence
text-classClassValueundefined CSS class (or classes) to add to the text component
variantColorVariant | nullnull Applies one of the Bootstrap theme color variants to the component. When implemented `bg-variant` and `text-variant` will take precedence
wrapper-attrsReadonly<AttrsValue>undefined Attributes to be applied to the wrapper element
NameScopeDescription
defaultContent to place in the dropdown text