Movatterモバイル変換


[0]ホーム

URL:


Framework:


Hire UsGet CoreUI PRO all-access

React Dropdown Component

Dropdown

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

Other Frameworks

CoreUI components are available as native Angular, Bootstrap (Vanilla JS), and Vue components. To learn more please visit the following pages.

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 declaresposition: 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:

And with<a> elements:

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

Split button#

Similarly, create split button dropdowns with virtually the same markup as single button dropdowns, but with the addition of boolean propsplit for proper spacing around the dropdown caret.

We use this extra class to reduce the horizontalpadding on either side of the caret by 25% and remove themargin-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.

Sizing#

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

Dark dropdowns#

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

And putting it to use in a navbar:

Directions#

RTL

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

Centered#

Make the dropdown menu centered below the toggle by addingdirection="center" to the<CDropdown> component.

Dropup#

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

Dropup centered#

Make the dropup menu centered above the toggle by addingdirection="dropup-center" to the<CDropdown> component.

Dropend#

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

Dropstart#

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

Menu items#

Historically dropdown menu contentshad 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.


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

Active#

Set boolean propertyactive tostyle item as active.

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

Disabled#

Adddisabled boolean property to items in the dropdown tostyle them as disabled.

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

Menu alignment#

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

Heads up! Dropdowns are positioned thanks to Popper.

Responsive alignment#

If you use responsive alignment, dynamic positioning is disabled.

To alignright the dropdown menu with the given breakpoint or larger, addaligment="xs|sm|md|lg|xl|xxl: end".

To alignleft the dropdown menu with the given breakpoint or larger, addaligment="xs|sm|md|lg|xl|xxl: start".

Menu content#

Headers#

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

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

Dividers#

Separate groups of related menu items with a divider.

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

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.

Forms#

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

Dropdown options#

Useoffset to displace the dropdown from its default position. The value is a string with two numbers separated by a comma, e.g.offset={[10, 20]}. Useportal property to render dropdowns inbody instead of the parent element. This helps to avoid any overflow or z-index issues.

Auto close behavior#

By default, dropdowns are closed when clicking outside of the dropdown menu or the toggle button. You can change this behavior with theautoClose property. SetautoClose to:

  • true - Close on clicks inside or outside of the React.js dropdown menu.
  • false - Disable auto-close; close manually by setting thevisible={false} (also not closed byEscape).
  • 'inside' - Close only when clicking inside the React.js dropdown menu.
  • 'outside' - Close only when clicking outside the React.js dropdown menu.

API#

Check out the documentation below for a comprehensive guide to all the props you can use with the components mentioned here.

CoreUI for React is Open Source UI Components Library for React.js.

CoreUI code licensedMIT, docsCC BY 3.0. CoreUI PRO requires acommercial license.


[8]ページ先頭

©2009-2025 Movatter.jp