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.
Dropdown Directions
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'.
Menu Alignment
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.
Dropdown Menus
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
DropdownButton
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
| Name | Type | Default | Description |
|---|---|---|---|
| disabled | boolean | Disables both Buttons | |
| href | string | An | |
| 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 | |
| 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
| Name | Type | Default | Description |
|---|---|---|---|
| disabled | boolean | Disables both Buttons | |
| href | string | An | |
| 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 | |
| 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 | |
| title required | node | The content of the non-toggle Button. | |
| toggleLabel | string | 'Toggle dropdown' | Accessible label for the toggle; the value of |
| type | string | 'button' | A |
| variant | string | ||
| bsPrefix | string |
Dropdown
import Dropdown from `@trimbleinc/modus-react-bootstrap/Dropdown`| Name | Type | Default | Description |
|---|---|---|---|
| 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
The Default behavior is | |
| navbar | boolean | false | |
| onSelect | function | A callback fired when a menu item is selected. | |
| onToggle | function | controls showA callback fired when the Dropdown wishes to change visibility. Called with the requested
| |
| show | boolean | controlled by: onToggle, initial prop: defaultShowWhether or not the Dropdown is visible. | |
| bsPrefix | string | 'dropdown' |
Dropdown.Toggle
import Dropdown.Toggle from `@trimbleinc/modus-react-bootstrap/Dropdown.Toggle`| Name | Type | Default | Description |
|---|---|---|---|
| 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' |
Dropdown.Menu
import Dropdown.Menu from `@trimbleinc/modus-react-bootstrap/Dropdown.Menu`| Name | Type | Default | Description |
|---|---|---|---|
| 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 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 If providing a custom, non DOM, component. the |
| 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
| |
| show | boolean | Controls the visibility of the Dropdown menu | |
| bsPrefix | string | 'dropdown-menu' |
Dropdown.Item
import Dropdown.Item from `@trimbleinc/modus-react-bootstrap/Dropdown.Item`| Name | Type | Default | Description |
|---|---|---|---|
| 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 | |
| href | string | HTML | |
| onClick | function | Callback fired when the menu item is clicked. | |
| onSelect | function | Callback fired when the menu item is selected. | |
| bsPrefix | string | 'dropdown-item' |
Dropdown.Header
import Dropdown.Header from `@trimbleinc/modus-react-bootstrap/Dropdown.Header`| Name | Type | Default | Description |
|---|---|---|---|
| as | elementType | <div> | |
| bsPrefix required | string | 'dropdown-header' |
Dropdown.Divider
import Dropdown.Divider from `@trimbleinc/modus-react-bootstrap/Dropdown.Divider`| Name | Type | Default | Description |
|---|---|---|---|
| as | elementType | <div> | |
| bsPrefix required | string | 'dropdown-divider' |