Overview

Please read this article when using dropdown menu for more styles and JavaScript calls. React Bootstrap Dropdown.

The basic Dropdown is composed of a wrapping Dropdown and inner <DropdownMenu>, and <DropdownToggle>. By default the <DropdownToggle> will render a Button component and accepts all the same props and adding a href prop will render an <a> element.

React bootstrap also provides the <DropdownButton> component to help reduce typing, provide a title prop and some DropdownItems.

Simple Button Dropdowns

Color Variants

Button Dropdowns can be any variety of button style and color. Simply use the desired variant.

Split Button

Split dropdown can be created by combining the Dropdown components with another Buttonand a ButtonGroup.

Dropdown Button Sizing

To change the size of the dropdown button use the prop size=sm, size=lg.

Icon Button Dropdowns

Icon buttons can also function as dropdowns. Simply set bsPrefix to nothing to remove dropdown-toggle class and eliminate the caret icon.

Trigger dropdown menus above, below, left, or to the right of their toggle elements, with the drop prop and the values 'up', 'down', 'left', 'right'.

By default, a dropdown menu is aligned to the left, but you can switch it by passing right to the align prop on a DropdownMenu or passing right to the menuAlign prop on the DropdownButton or DropdownsSplitButton as seen below.

You can optionally use button elements in your dropdowns instead of links.

Sizes

For niche cases, dropdown menus can be given a max-height using the following classes:

  • .dropdown-menu-sm- 140px
  • .dropdown-menu-md - 240px
  • .dropdown-menu-lg - 400px

Active

Add an DropdownsActive prop to items to style them as DropdownsActive.

Disabled

Add an DropdownsDisabled prop to items to style them as DropdownsDisabled.

Headers

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

Dividers

Separate groups of related menu items with a divider.

Text

Place any freeform DropdownsText within a dropdown menu with DropdownsText. Note: you’ll likely need additional sizing styles to constrain the menu width.

Forms

Put a form within a dropdown menu, or make it into a dropdown menu, and usemargin or padding utilities to give it the negative space you require.

API

import DropdownButton from `@trimbleinc/modus-react-bootstrap/DropdownButton`

A convenience component for simple or general use dropdowns. Renders a Button toggle and all children are passed directly to the default Dropdown.Menu. This component accepts all of Dropdown's props.

All unknown props are passed through to the Dropdown component. Only the Button variant, size and bsPrefix props are passed to the toggle, along with menu-related props are passed to the Dropdown.Menu

NameTypeDefaultDescription
disabled
boolean

Disables both Buttons

href
string

An href passed to the Toggle component

id required
string|number

An html id attribute for the Toggle button, necessary for assistive technologies, such as screen readers.

menuAlign
"left"|"right"|{ sm: "left"|"right" }|{ md: "left"|"right" }|{ lg: "left"|"right" }|{ xl: "left"|"right"}

Aligns the dropdown menu responsively.

see DropdownMenu for more details

menuRole
string

An ARIA accessible role applied to the Menu component. When set to 'menu', The dropdown

onClick
function

An onClick handler passed to the Toggle component

renderMenuOnMount
boolean

Whether to render the dropdown menu in the DOM before the first time it is shown

rootCloseEvent
string

Which event when fired outside the component will cause it to be closed.

see DropdownMenu for more details

size
string
title required
node

The content of the non-toggle Button.

variant
string
bsPrefix
string

SplitButton

import SplitButton from `@trimbleinc/modus-react-bootstrap/SplitButton`

A convenience component for simple or general use split button dropdowns. Renders a ButtonGroup containing a Button and a Button toggle for the Dropdown. All children are passed directly to the default Dropdown.Menu. This component accepts all of Dropdown's props.

All unknown props are passed through to the Dropdown component. The Button variant, size and bsPrefix props are passed to the button and toggle, and menu-related props are passed to the Dropdown.Menu

NameTypeDefaultDescription
disabled
boolean

Disables both Buttons

href
string

An href passed to the non-toggle Button

id required
string|number

An html id attribute for the Toggle button, necessary for assistive technologies, such as screen readers.

menuAlign
"left"|"right"|{ sm: "left"|"right" }|{ md: "left"|"right" }|{ lg: "left"|"right" }|{ xl: "left"|"right"}

Aligns the dropdown menu responsively.

see DropdownMenu for more details

menuRole
string

An ARIA accessible role applied to the Menu component. When set to 'menu', The dropdown

onClick
function

An onClick handler passed to the non-toggle Button

renderMenuOnMount
boolean

Whether to render the dropdown menu in the DOM before the first time it is shown

rootCloseEvent
string

Which event when fired outside the component will cause it to be closed.

see DropdownMenu for more details

size
string
target
string

An anchor target passed to the non-toggle Button

title required
node

The content of the non-toggle Button.

toggleLabel
string
'Toggle dropdown'

Accessible label for the toggle; the value of title if not specified.

type
string
'button'

A type passed to the non-toggle Button

variant
string
bsPrefix
string
import Dropdown from `@trimbleinc/modus-react-bootstrap/Dropdown`
NameTypeDefaultDescription
alignRight
boolean

Align the menu to the right side of the Dropdown toggle

as
elementType
drop
'up' | 'left' | 'right' | 'down'

Determines the direction and location of the Menu in relation to it's Toggle.

flip
boolean

Allow Dropdown to flip in case of an overlapping on the reference element. For more information refer to Popper.js's flip docs.

focusFirstItemOnShow
false | true | 'keyboard'

Controls the focus behavior for when the Dropdown is opened. Set to true to always focus the first menu item, keyboard to focus only when navigating via the keyboard, or false to disable completely

The Default behavior is false unless the Menu has a role="menu" where it will default to keyboard to match the recommended ARIA Authoring practices.

navbar
boolean
false
onSelect
function

A callback fired when a menu item is selected.

(eventKey: any, event: Object) => any
onToggle
function
controls show

A callback fired when the Dropdown wishes to change visibility. Called with the requested show value, the DOM event, and the source that fired it: 'click','keydown','rootClose', or 'select'.

function(
  isOpen: boolean,
  event: SyntheticEvent,
  metadata: {
    source: 'select' | 'click' | 'rootClose' | 'keydown'
  }
): void
show
boolean
controlled by: onToggle, initial prop: defaultShow

Whether or not the Dropdown is visible.

bsPrefix
string
'dropdown'
import Dropdown.Toggle from `@trimbleinc/modus-react-bootstrap/Dropdown.Toggle`
NameTypeDefaultDescription
as
elementType
<Button>
childBsPrefix
string

to passthrough to the underlying button or whatever from DropdownButton

id required
string|number

An html id attribute, necessary for assistive technologies, such as screen readers.

split
boolean
bsPrefix
string
'dropdown-toggle'
import Dropdown.Menu from `@trimbleinc/modus-react-bootstrap/Dropdown.Menu`
NameTypeDefaultDescription
align
"left"|"right"|{ sm: "left"|"right" }|{ md: "left"|"right" }|{ lg: "left"|"right" }|{ xl: "left"|"right"}
'left'

Aligns the dropdown menu to the specified side of the container. You can also align the menu responsively for breakpoints starting at sm and up. The alignment direction will affect the specified breakpoint or larger.

Note: Using responsive alignment will disable Popper usage for positioning.

alignRight
boolean
false
Deprecated: Use align="right"

Aligns the Dropdown menu to the right of it's container.

as
elementType
<div>

Control the rendering of the DropdownMenu. All non-menu props (listed here) are passed through to the as Component.

If providing a custom, non DOM, component. the show, close and alignRight props are also injected and should be handled appropriately.

flip
boolean
true

Have the dropdown switch to it's opposite placement when necessary to stay on screen.

onSelect
function
popperConfig
object

A set of popper options and props passed directly to Popper.

renderOnMount
boolean

Whether to render the dropdown menu in the DOM before the first time it is shown

rootCloseEvent
'click' | 'mousedown'

Which event when fired outside the component will cause it to be closed

Note: For custom dropdown components, you will have to pass the rootCloseEvent to <RootCloseWrapper> in your custom dropdown menu component (similarly to how it is implemented in <Dropdown.Menu>).

show
boolean

Controls the visibility of the Dropdown menu

bsPrefix
string
'dropdown-menu'
import Dropdown.Item from `@trimbleinc/modus-react-bootstrap/Dropdown.Item`
NameTypeDefaultDescription
active
boolean

Highlight the menu item as active.

as
elementType
<SafeAnchor>
disabled
boolean
false

Disable the menu item, making it unselectable.

eventKey
string | number

Value passed to the onSelect handler, useful for identifying the selected menu item.

href
string

HTML href attribute corresponding to a.href.

onClick
function

Callback fired when the menu item is clicked.

onSelect
function

Callback fired when the menu item is selected.

(eventKey: any, event: Object) => any
bsPrefix
string
'dropdown-item'
import Dropdown.Header from `@trimbleinc/modus-react-bootstrap/Dropdown.Header`
NameTypeDefaultDescription
as
elementType
<div>
bsPrefix required
string
'dropdown-header'
import Dropdown.Divider from `@trimbleinc/modus-react-bootstrap/Dropdown.Divider`
NameTypeDefaultDescription
as
elementType
<div>
bsPrefix required
string
'dropdown-divider'