DropdownButtons are a specialized form of Button in which the button itself does not invoke any action but instead presents a list of actions in a dropdown menu.
Different dropdown button types (styles) have different contextual meaning in the application. Use the type
property to specify the appropriate dropdown button type.
There are three supported dropdown button sizes: 'lg'
(the default), 'md'
and 'sm'
. Use the size
property to set the appropriate size.
Set the disabled
property to change the dropdown button’s state to disabled.
Set the allowFocusOnDisable
property to true
, along with the disabled
property. This allows a button to receive focus when it is disabled by keeping it in the tab cycle. This is good practice for accessibility, as it prevents the button from being hidden from assistive technologies (like screen readers). Further, if allowFocusOnDisable
is true
, then the disabledMessage
and enabledMessage
properties MUST also be set to a localized string. These messages should be such that they help users of accessible technologies understand the button’s state changes.
In cases when the text of a button may change, use a label to describe the button. Set the textLabel
property to add a label for a button.
NOTE: By default, the font weight of the text label matches the font weight of the button text. If you choose to alter the font weight of the text label, it may not line up properly with the button text due to font rendering inconsistencies between browsers.
Dropdown menus are composed of a collection of 1 or more MenuGroup
and MenuItem
components. MenuGroup
components accept a header
prop which renders a group title list item.
Property | Type | Default | Description |
---|---|---|---|
id | String | Required | id attribute of the <button> tag. Required for accessibility. |
title | Node | Required | Content (usually text) displayed on the button. |
disabledMessage | String | Required if allowFocusOnDisable is true | A visually hidden hint message to be conveyed to users of assistive technologies like screen readers, when button changes state to disabled. This message should explain why this action is disabled or how to enable it. For example, “This action is restricted to some users” OR “Please fill required fields before submitting” |
enabledMessage | String | Required if allowFocusOnDisable is true | A visually hidden hint message to be conveyed to users of assistive technologies like screen readers, when button changes state to enabled. This message should call out the fact that this action is now enabled. For example, “Press submit to proceed” |
allowFocusOnDisable | Boolean | false | Setting this to true allows the button to receive focus when it is disabled. |
buttonClassName | String | Custom classes to be added to the <button> tag. | |
children | Node | Collection of MenuItem components to be shown in the dropdown menu. | |
className | String | Custom classes to be added to the containing <div> tag. | |
disabled | Boolean | false | Controls whether the button is enabled or disabled. |
dropdownMaxHeight | Number | Overrides the maximum height of the dropdown menu (in pixels). | |
flipContainer | Element or Element[] | Used to create a boundary for the underlying Popper to stay within. | |
muted | Boolean | false | Renders the button in an alternate “muted” style where the background color is white and the border color is the brand color for the type. |
noCaret | Boolean | false | Controls whether the caret (“^”) shows on the button after the title . |
open | Boolean | false | Controls whether the dropdown is visible when initially rendered. |
placement | String or String[] | ['bottom-start', 'top-start', 'bottom-end', 'top-end'] | Placement of the popover relative to the target element. Options are 'auto' , 'auto-start' , 'auto-end' , 'top' , 'top-start' , 'top-end' , 'bottom' , 'bottom-start' , 'bottom-end' , 'left' , 'left-start' , 'left-end' , 'right' , 'right-start' , 'right-end' . If you use an array of strings, the first item in the array is the default placement and the following ones are chosen in order as fallback placements if the preceding ones don’t work. |
pullRight | Boolean | false | Aligns the right edge of the dropdown with the right edge of the button. |
size | String | 'lg' | Button size. Options are 'lg' , 'md' , 'sm' . |
textLabel | Node | Label text that describes a button. This text will appear to the left of the button. | |
textLabelClassName | String | Custom classes to be added to the <div> tag around the text label. | |
type | String | 'default' | Button type. Options are 'default' , 'primary' , 'create' , 'link' . |
Property | Parameters | Description |
---|---|---|
onClose | Callback function fired when dropdown closes. | |
onSelect | eventKey , event | Callback function fired when a menu item is selected. |
onToggle | isOpen , event , source | Callback function fired when the dropdown changes visibility. |
Property | Type | Default | Description |
---|---|---|---|
children | Node | One or more MenuItem components | |
className | String | Custom classes to be added to the <ul> tag. | |
header | String | Adds a header to the group of MenuItems which is not focusable or selectable. |
Property | Parameters | Description |
---|---|---|
onSelect | eventKey , event | Callback function fired when a menu item is selected. |
Property | Type | Default | Description |
---|---|---|---|
active | Boolean | Adds an active class, aria-checked, and role attribute to the <li> tag. | |
children | Node | Text to display inside of anchor tag or list item. | |
className | String | Custom classes to be added to the <li> tag. | |
disabled | Boolean | false | Show the item as disabled, which is not selectable. |
divider | Boolean | false | Add a horizontal divider in the menu. |
eventKey | String | Value passed to the onSelect callback to identify the item selected. | |
href | String | Location to which the applicaton will navigate when item is selected. |
Property | Parameters | Description |
---|---|---|
onClick | event | Callback function fired when the menu item is clicked. |
onKeyDown | event | Callback function fired when the key is pressed on a menu item. |
onSelect | eventKey , event | Callback function fired when the menu item is selected. |