React Dropdown Component

React dropdown component allows you to toggle contextual overlays for displaying lists, links, and more html elements.

Overview#

Dropdowns are toggleable, contextual overlays for displaying lists of links and more.

Dropdowns are built on a third party library, Popper.js, which provides dynamic positioning and viewport detection. Popper.js isn't used to position dropdowns in navbars though as dynamic positioning isn't required.

Examples#

Bind the dropdown's toggle and the dropdown menu inside <CDropdown>, or different element that declares position: relative;. Dropdowns can be triggered from <a> or <button> elements to better fit your possible requirements.

Single button#

Here's how you can put them to work with either <button> elements:

1<CDropdown>
2 <CDropdownToggle color="secondary">Dropdown button</CDropdownToggle>
3 <CDropdownMenu>
4 <CDropdownItem href="#">Action</CDropdownItem>
5 <CDropdownItem href="#">Another action</CDropdownItem>
6 <CDropdownItem href="#">Something else here</CDropdownItem>
7 </CDropdownMenu>
8</CDropdown>

And with <a> elements:

1<CDropdown>
2 <CDropdownToggle href="#" color="secondary">
3 Dropdown button
4 </CDropdownToggle>
5 <CDropdownMenu>
6 <CDropdownItem href="#">Action</CDropdownItem>
7 <CDropdownItem href="#">Another action</CDropdownItem>
8 <CDropdownItem href="#">Something else here</CDropdownItem>
9 </CDropdownMenu>
10</CDropdown>

The best part is you can do this with any button variant, too:

1<>
2 {['primary', 'secondary', 'success', 'info', 'warning', 'danger'].map((color, index) => (
3 <CDropdown variant="btn-group" key={index}>
4 <CDropdownToggle color={color}>{color}</CDropdownToggle>
5 <CDropdownMenu>
6 <CDropdownItem href="#">Action</CDropdownItem>
7 <CDropdownItem href="#">Another action</CDropdownItem>
8 <CDropdownItem href="#">Something else here</CDropdownItem>
9 <CDropdownDivider />
10 <CDropdownItem href="#">Separated link</CDropdownItem>
11 </CDropdownMenu>
12 </CDropdown>
13 ))}
14</>

Split button#

Similarly, create split button dropdowns with virtually the same markup as single button dropdowns, but with the addition of boolean prop 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 attached for normal button dropdowns. Those additional changes hold the caret centered in the split button and implement a more properly sized hit area next to the main button.

1<>
2 {['primary', 'secondary', 'success', 'info', 'warning', 'danger'].map((color, index) => (
3 <CDropdown variant="btn-group" key={index}>
4 <CButton color={color}>{color}</CButton>
5 <CDropdownToggle color={color} split />
6 <CDropdownMenu>
7 <CDropdownItem href="#">Action</CDropdownItem>
8 <CDropdownItem href="#">Another action</CDropdownItem>
9 <CDropdownItem href="#">Something else here</CDropdownItem>
10 <CDropdownDivider />
11 <CDropdownItem href="#">Separated link</CDropdownItem>
12 </CDropdownMenu>
13 </CDropdown>
14 ))}
15</>

Sizing#

Button dropdowns work with buttons of all sizes, including default and split dropdown buttons.

1<CDropdown variant="btn-group">
2 <CDropdownToggle color="secondary" size="lg">Large button</CDropdownToggle>
3 <CDropdownMenu>
4 <CDropdownItem href="#">Action</CDropdownItem>
5 <CDropdownItem href="#">Another action</CDropdownItem>
6 <CDropdownItem href="#">Something else here</CDropdownItem>
7 <CDropdownDivider/>
8 <CDropdownItem href="#">Separated link</CDropdownItem>
9 </CDropdownMenu>
10 </CDropdown>
11
12 <CDropdown variant="btn-group">
13 <CButton color="secondary" size="lg">Large split button</CButton>
14 <CDropdownToggle color="secondary" size="lg" split/>
15 <CDropdownMenu>
16 <CDropdownItem href="#">Action</CDropdownItem>
17 <CDropdownItem href="#">Another action</CDropdownItem>
18 <CDropdownItem href="#">Something else here</CDropdownItem>
19 <CDropdownDivider/>
20 <CDropdownItem href="#">Separated link</CDropdownItem>
21 </CDropdownMenu>
22 </CDropdown>
1<CDropdown variant="btn-group">
2 <CDropdownToggle color="secondary" size="sm">Small button</CDropdownToggle>
3 <CDropdownMenu>
4 <CDropdownItem href="#">Action</CDropdownItem>
5 <CDropdownItem href="#">Another action</CDropdownItem>
6 <CDropdownItem href="#">Something else here</CDropdownItem>
7 <CDropdownDivider/>
8 <CDropdownItem href="#">Separated link</CDropdownItem>
9 </CDropdownMenu>
10 </CDropdown>
11
12 <CDropdown variant="btn-group">
13 <CButton color="secondary" size="sm">Small split button</CButton>
14 <CDropdownToggle color="secondary" size="sm"split/>
15 <CDropdownMenu>
16 <CDropdownItem href="#">Action</CDropdownItem>
17 <CDropdownItem href="#">Another action</CDropdownItem>
18 <CDropdownItem href="#">Something else here</CDropdownItem>
19 <CDropdownDivider/>
20 <CDropdownItem href="#">Separated link</CDropdownItem>
21 </CDropdownMenu>
22 </CDropdown>

Dark dropdowns#

Opt into darker dropdowns to match a dark navbar or custom style by set dark property. No changes are required to the dropdown items.

1<CDropdown dark>
2 <CDropdownToggle color="secondary">Dropdown button</CDropdownToggle>
3 <CDropdownMenu>
4 <CDropdownItem href="#">Action</CDropdownItem>
5 <CDropdownItem href="#">Another action</CDropdownItem>
6 <CDropdownItem href="#">Something else here</CDropdownItem>
7 <CDropdownDivider />
8 <CDropdownItem href="#">Separated link</CDropdownItem>
9 </CDropdownMenu>
10</CDropdown>

And putting it to use in a navbar:

1<CNavbar expand="lg" colorScheme="dark" className="bg-dark">
2 <CContainer fluid>
3 <CNavbarBrand href="#">Navbar</CNavbarBrand>
4 <CNavbarToggler aria-label="Toggle navigation" aria-expanded={true} />
5 <CCollapse className="navbar-collapse" visible={true}>
6 <CNavbarNav>
7 <CDropdown dark component="li" variant="nav-item">
8 <CDropdownToggle>Dropdown</CDropdownToggle>
9 <CDropdownMenu>
10 <CDropdownItem href="#">Action</CDropdownItem>
11 <CDropdownItem href="#">Another action</CDropdownItem>
12 <CDropdownItem href="#">Something else here</CDropdownItem>
13 <CDropdownDivider />
14 <CDropdownItem href="#">Separated link</CDropdownItem>
15 </CDropdownMenu>
16 </CDropdown>
17 </CNavbarNav>
18 </CCollapse>
19 </CContainer>
20</CNavbar>

Directions#

RTL

Directions are mirrored when using CoreUI in RTL, meaning `.dropstart` will appear on the right side.

Dropup#

Trigger dropdown menus above elements by adding direction="dropup" to the <CDropdown> component.

1<CDropdown variant="btn-group" direction="dropup">
2 <CDropdownToggle color="secondary">Dropdown</CDropdownToggle>
3 <CDropdownMenu>
4 <CDropdownItem href="#">Action</CDropdownItem>
5 <CDropdownItem href="#">Another action</CDropdownItem>
6 <CDropdownItem href="#">Something else here</CDropdownItem>
7 <CDropdownDivider/>
8 <CDropdownItem href="#">Separated link</CDropdownItem>
9 </CDropdownMenu>
10 </CDropdown>
11
12 <CDropdown variant="btn-group" direction="dropup">
13 <CButton color="secondary" >Small split button</CButton>
14 <CDropdownToggle color="secondary" split/>
15 <CDropdownMenu>
16 <CDropdownItem href="#">Action</CDropdownItem>
17 <CDropdownItem href="#">Another action</CDropdownItem>
18 <CDropdownItem href="#">Something else here</CDropdownItem>
19 <CDropdownDivider/>
20 <CDropdownItem href="#">Separated link</CDropdownItem>
21 </CDropdownMenu>
22 </CDropdown>

Dropright#

Trigger dropdown menus at the right of the elements by adding direction="dropend" to the <CDropdown> component.

1<CDropdown variant="btn-group" direction="dropend">
2 <CDropdownToggle color="secondary">Dropdown</CDropdownToggle>
3 <CDropdownMenu>
4 <CDropdownItem href="#">Action</CDropdownItem>
5 <CDropdownItem href="#">Another action</CDropdownItem>
6 <CDropdownItem href="#">Something else here</CDropdownItem>
7 <CDropdownDivider/>
8 <CDropdownItem href="#">Separated link</CDropdownItem>
9 </CDropdownMenu>
10 </CDropdown>
11
12 <CDropdown variant="btn-group" direction="dropend">
13 <CButton color="secondary" >Small split button</CButton>
14 <CDropdownToggle color="secondary" split/>
15 <CDropdownMenu>
16 <CDropdownItem href="#">Action</CDropdownItem>
17 <CDropdownItem href="#">Another action</CDropdownItem>
18 <CDropdownItem href="#">Something else here</CDropdownItem>
19 <CDropdownDivider/>
20 <CDropdownItem href="#">Separated link</CDropdownItem>
21 </CDropdownMenu>
22 </CDropdown>

Dropleft#

Trigger dropdown menus at the left of the elements by adding direction="dropstart" to the <CDropdown> component.

1<CDropdown variant="btn-group" direction="dropstart">
2 <CDropdownToggle color="secondary">Dropdown</CDropdownToggle>
3 <CDropdownMenu>
4 <CDropdownItem href="#">Action</CDropdownItem>
5 <CDropdownItem href="#">Another action</CDropdownItem>
6 <CDropdownItem href="#">Something else here</CDropdownItem>
7 <CDropdownDivider/>
8 <CDropdownItem href="#">Separated link</CDropdownItem>
9 </CDropdownMenu>
10 </CDropdown>
11
12 <CButtonGroup>
13 <CDropdown variant="btn-group" direction="dropstart">
14 <CDropdownToggle color="secondary" split/>
15 <CDropdownMenu>
16 <CDropdownItem href="#">Action</CDropdownItem>
17 <CDropdownItem href="#">Another action</CDropdownItem>
18 <CDropdownItem href="#">Something else here</CDropdownItem>
19 <CDropdownDivider/>
20 <CDropdownItem href="#">Separated link</CDropdownItem>
21 </CDropdownMenu>
22 </CDropdown>
23 <CButton color="secondary" >Small split button</CButton>
24 </CButtonGroup>

Historically dropdown menu contents had to be links, but that's no longer the case with v4. Now you can optionally use <button> elements in your dropdowns instead of just <a>s.

1<CDropdown>
2 <CDropdownToggle color="secondary">Dropdown</CDropdownToggle>
3 <CDropdownMenu>
4 <CDropdownItem component="button">Action</CDropdownItem>
5 <CDropdownItem component="button">Another action</CDropdownItem>
6 <CDropdownItem component="button">Something else here</CDropdownItem>
7 <CDropdownDivider />
8 <CDropdownItem component="button">Separated link</CDropdownItem>
9 </CDropdownMenu>
10</CDropdown>

You can also create non-interactive dropdown items with <CDropdownItemPlain>.

1<div className="border rounded py-2">
2 <CDropdownItemPlain>Dropdown item text</CDropdownItemPlain>
3 <CDropdownItem href="#">Action</CDropdownItem>
4 <CDropdownItem href="#">Another action</CDropdownItem>
5 <CDropdownItem href="#">Something else here</CDropdownItem>
6</div>

Active#

Set boolean property active to style item as active.

In the following example we use div instead of <CDropdownMenu> to show <CDropdownMenu> content.

1<div className="border rounded py-2">
2 <CDropdownItem href="#">Regular link</CDropdownItem>
3 <CDropdownItem href="#" active>
4 Active link
5 </CDropdownItem>
6 <CDropdownItem href="#">Another link</CDropdownItem>
7</div>

Disabled#

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

In the following example we use div instead of <CDropdownMenu> to show <CDropdownMenu> content.

1<div className="border rounded py-2">
2 <CDropdownItem href="#">Regular link</CDropdownItem>
3 <CDropdownItem href="#" disabled>
4 Disabled link
5 </CDropdownItem>
6 <CDropdownItem href="#">Another link</CDropdownItem>
7</div>

By default, a dropdown menu is automatically positioned 100% from the top and along the left side of its parent. Add aligment="end" to right align the dropdown menu.

Heads up! Dropdowns are positioned thanks to Popper.
1<CDropdown alignment="end">
2 <CDropdownToggle color="secondary">Right-aligned menu example</CDropdownToggle>
3 <CDropdownMenu>
4 <CDropdownItem href="#">Action</CDropdownItem>
5 <CDropdownItem href="#">Another action</CDropdownItem>
6 <CDropdownItem href="#">Something else here</CDropdownItem>
7 <CDropdownDivider />
8 <CDropdownItem href="#">Separated link</CDropdownItem>
9 </CDropdownMenu>
10</CDropdown>

Responsive alignment#

If you use responsive alignment, dynamic positioning is disabled.

To align right the dropdown menu with the given breakpoint or larger, add aligment="xs|sm|md|lg|xl|xxl: end".

1<CDropdown alignment={{ lg: 'end' }}>
2 <CDropdownToggle color="secondary">
3 Left-aligned but right aligned when large screen
4 </CDropdownToggle>
5 <CDropdownMenu>
6 <CDropdownItem href="#">Action</CDropdownItem>
7 <CDropdownItem href="#">Another action</CDropdownItem>
8 <CDropdownItem href="#">Something else here</CDropdownItem>
9 <CDropdownDivider />
10 <CDropdownItem href="#">Separated link</CDropdownItem>
11 </CDropdownMenu>
12</CDropdown>

To align left the dropdown menu with the given breakpoint or larger, add aligment="xs|sm|md|lg|xl|xxl: start".

1<CDropdown alignment={{ xs: 'end', lg: 'start' }}>
2 <CDropdownToggle color="secondary">
3 Right-aligned but left aligned when large screen
4 </CDropdownToggle>
5 <CDropdownMenu>
6 <CDropdownItem href="#">Action</CDropdownItem>
7 <CDropdownItem href="#">Another action</CDropdownItem>
8 <CDropdownItem href="#">Something else here</CDropdownItem>
9 <CDropdownDivider />
10 <CDropdownItem href="#">Separated link</CDropdownItem>
11 </CDropdownMenu>
12</CDropdown>

Headers#

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

In the following example we use div instead of <CDropdownMenu> to show <CDropdownMenu> content.

ActionAnother action
1<div className="border rounded py-2">
2 <CDropdownHeader>Dropdown header</CDropdownHeader>
3 <CDropdownItem href="#">Action</CDropdownItem>
4 <CDropdownItem href="#">Another action</CDropdownItem>
5</div>

Dividers#

Separate groups of related menu items with a divider.

In the following example we use div instead of <CDropdownMenu> to show <CDropdownMenu> content.

1<div className="border rounded py-2">
2 <CDropdownItem href="#">Action</CDropdownItem>
3 <CDropdownItem href="#">Another action</CDropdownItem>
4 <CDropdownItem href="#">Something else here</CDropdownItem>
5 <CDropdownDivider />
6 <CDropdownItem href="#">Separated link</CDropdownItem>
7</div>

Text#

Place any freeform text within a dropdown menu with text. Note that you'll likely need additional sizing styles to constrain the menu width.

Some example text that's free-flowing within the dropdown menu.

And this is more example text.

1<div className="border rounded p-4 text-medium-emphasis" style={{ maxWidth: '200px' }}>
2 <p>Some example text that's free-flowing within the dropdown menu.</p>
3 <p className="mb-0">And this is more example text.</p>
4</div>

Forms#

Put a form within a dropdown menu, or make it into a dropdown menu.

New around here? Sign upForgot password?
1<div className="border rounded py-2">
2 <CForm className="px-4 py-4">
3 <div className="mb-3">
4 <CFormLabel htmlFor="exampleDropdownFormEmail1">Email address</CFormLabel>
5 <CFormInput type="email" id="exampleDropdownFormEmail1" placeholder="[email protected]" />
6 </div>
7 <div className="mb-3">
8 <CFormLabel htmlFor="exampleDropdownFormPassword1">Password</CFormLabel>
9 <CFormInput type="password" id="exampleDropdownFormPassword1" placeholder="Password" />
10 </div>
11 <div className="mb-3">
12 <CFormCheck id="dropdownCheck" label="Remember me" />
13 </div>
14 <CButton type="submit">Sign in</CButton>
15 </CForm>
16 <CDropdownDivider />
17 <CDropdownItem href="#">New around here? Sign up</CDropdownItem>
18 <CDropdownItem href="#">Forgot password?</CDropdownItem>
19</div>

API#

CDropdown#

1import { CDropdown } from '@coreui/react'
2// or
3import CDropdown from '@coreui/react/src/components/dropdown/CDropdown'
PropertyDescriptionTypeDefault
alignmentSet aligment of dropdown menu.'start' | 'end' | { xs: 'start' | 'end' } | { sm: 'start' | 'end' } | { md: 'start' | 'end' } | { lg: 'start' | 'end' } | { xl: 'start' | 'end'} | { xxl: 'start' | 'end'}-
classNameA string of all className you want applied to the base component.string-
componentComponent used for the root node. Either a string to use a HTML element or a component.string | ComponentClass<any, any> | FunctionComponent<any>div
darkSets a darker color scheme to match a dark navbar.boolean-
directionSets a specified direction and location of the dropdown menu.'dropup' | 'dropend' | 'dropstart'-
onHideCallback fired when the component requests to be hidden.() => void-
onShowCallback fired when the component requests to be shown.() => void-
placementDescribes the placement of your component after Popper.js has applied all the modifiers that may have flipped or altered the originally provided placement property.'auto' | 'top-end' | 'top' | 'top-start' | 'bottom-end' | 'bottom' | 'bottom-start' | 'right-start' | 'right' | 'right-end' | 'left-start' | 'left' | 'left-end'bottom-start
popperIf you want to disable dynamic positioning set this property to true.booleantrue
variantSet the dropdown variant to an btn-group, dropdown, input-group, and nav-item.'btn-group' | 'dropdown' | 'input-group' | 'nav-item'btn-group
visibleToggle the visibility of dropdown menu component.booleanfalse

CDropdownDivider#

1import { CDropdownDivider } from '@coreui/react'
2// or
3import CDropdownDivider from '@coreui/react/src/components/dropdown/CDropdownDivider'
PropertyDescriptionTypeDefault
classNameA string of all className you want applied to the component.string-

CDropdownHeader#

1import { CDropdownHeader } from '@coreui/react'
2// or
3import CDropdownHeader from '@coreui/react/src/components/dropdown/CDropdownHeader'
PropertyDescriptionTypeDefault
classNameA string of all className you want applied to the component.string-
componentComponent used for the root node. Either a string to use a HTML element or a component.string | ComponentClass<any, any> | FunctionComponent<any>-

CDropdownItem#

1import { CDropdownItem } from '@coreui/react'
2// or
3import CDropdownItem from '@coreui/react/src/components/dropdown/CDropdownItem'
PropertyDescriptionTypeDefault
activeToggle the active state for the component.boolean-
classNameA string of all className you want applied to the component.string-
componentComponent used for the root node. Either a string to use a HTML element or a component.string | ComponentClass<any, any> | FunctionComponent<any>a
disabledToggle the disabled state for the component.boolean-
hrefThe href attribute specifies the URL of the page the link goes to.string-

CDropdownItemPlain#

1import { CDropdownItemPlain } from '@coreui/react'
2// or
3import CDropdownItemPlain from '@coreui/react/src/components/dropdown/CDropdownItemPlain'
PropertyDescriptionTypeDefault
classNameA string of all className you want applied to the component.string-
componentComponent used for the root node. Either a string to use a HTML element or a component.string | ComponentClass<any, any> | FunctionComponent<any>-

CDropdownMenu#

1import { CDropdownMenu } from '@coreui/react'
2// or
3import CDropdownMenu from '@coreui/react/src/components/dropdown/CDropdownMenu'
PropertyDescriptionTypeDefault
classNameA string of all className you want applied to the base component.string-
componentComponent used for the root node. Either a string to use a HTML element or a component.string | ComponentClass<any, any> | FunctionComponent<any>-

CDropdownToggle#

1import { CDropdownToggle } from '@coreui/react'
2// or
3import CDropdownToggle from '@coreui/react/src/components/dropdown/CDropdownToggle'
PropertyDescriptionTypeDefault
activeToggle the active state for the component.boolean-
caretEnables pseudo element caret on toggler.booleantrue
classNameA string of all className you want applied to the base component.string-
colorSets the color context of the component to one of CoreUI’s themed colors.'primary' | 'secondary' | 'success' | 'danger' | 'warning' | 'info' | 'dark' | 'light' | string-
componentComponent used for the root node. Either a string to use a HTML element or a component.string | ComponentClass<any, any> | FunctionComponent<any>-
disabledToggle the disabled state for the component.boolean-
hrefThe href attribute specifies the URL of the page the link goes to.string-
roleThe role attribute describes the role of an element in programs that can make use of it, such as screen readers or magnifiers.string-
shapeSelect the shape of the component.'rounded' | 'rounded-top' | 'rounded-end' | 'rounded-bottom' | 'rounded-start' | 'rounded-circle' | 'rounded-pill' | 'rounded-0' | 'rounded-1' | 'rounded-2' | 'rounded-3' | string-
sizeSize the component small or large.'sm' | 'lg'-
splitSimilarly, create split button dropdowns with virtually the same markup as single button dropdowns, but with the addition of .dropdown-toggle-split className for proper spacing around the dropdown caret.boolean-
triggerSets which event handlers you’d like provided to your toggle prop. You can specify one trigger or an array of them.'hover' | 'focus' | 'click'click
variantSet the button variant to an outlined button or a ghost button.'outline' | 'ghost'-