A composable dropdown component that can handle both simple navigation menus as well as complex action menus with checkboxes, radios, and submenus.
import { Button, Dropdown } from '@fluxui-dev/react';import { ChevronDownIcon, PlusIcon, TrashIcon } from '@fluxui-dev/react/icons';<Dropdown> <Dropdown.Trigger> <Button iconTrailing={ChevronDownIcon}>Options</Button> </Dropdown.Trigger> <Dropdown.Menu> <Dropdown.Item icon={PlusIcon}>New post</Dropdown.Item> <Dropdown.Separator /> <Dropdown.Submenu heading="Sort by"> <Dropdown.RadioGroup defaultValue="name"> <Dropdown.Radio value="name">Name</Dropdown.Radio> <Dropdown.Radio value="date">Date</Dropdown.Radio> <Dropdown.Radio value="popularity">Popularity</Dropdown.Radio> </Dropdown.RadioGroup> </Dropdown.Submenu> <Dropdown.Submenu heading="Filter"> <Dropdown.Checkbox defaultChecked>Draft</Dropdown.Checkbox> <Dropdown.Checkbox defaultChecked>Published</Dropdown.Checkbox> <Dropdown.Checkbox>Archived</Dropdown.Checkbox> </Dropdown.Submenu> <Dropdown.Separator /> <Dropdown.Item variant="danger" icon={TrashIcon}>Delete</Dropdown.Item> </Dropdown.Menu></Dropdown>
Display a simple set of links in a dropdown menu.
<Dropdown position="bottom" align="end"> <Dropdown.Trigger> <Profile avatar="/img/demo/user.png" name="Olivia Martin" /> </Dropdown.Trigger> <Dropdown.Menu> <Dropdown.Item href="#" icon={UserIcon}>Account</Dropdown.Item> <Dropdown.Item href="#" icon={BuildingStorefrontIcon}>Profile</Dropdown.Item> <Dropdown.Item href="#" icon={CreditCardIcon}>Billing</Dropdown.Item> <Dropdown.Item href="#" icon={ArrowRightStartOnRectangleIcon}>Logout</Dropdown.Item> <Dropdown.Item href="#" icon={TrashIcon} variant="danger">Delete</Dropdown.Item> </Dropdown.Menu></Dropdown>
Customize the position of the dropdown menu via the position and align props. You can first pass the base position: top, bottom, left, and right, then an alignment modifier like start, center, or end.
<Dropdown position="top" align="start">{/* More positions... */}<Dropdown position="right" align="center"><Dropdown position="bottom" align="center"><Dropdown position="left" align="end">
Customize the offset/gap of the dropdown menu via the offset and gap props. These properties accept values in pixels.
<Dropdown offset={-15} gap={2}>
Add keyboard shortcut hints to menu items to teach users how to navigate your app faster.
<Dropdown> <Dropdown.Trigger> <Button iconTrailing={ChevronDownIcon}>Options</Button> </Dropdown.Trigger> <Dropdown.Menu> <Dropdown.Item icon={PencilSquareIcon} kbd="⌘S">Save</Dropdown.Item> <Dropdown.Item icon={DocumentDuplicateIcon} kbd="⌘D">Duplicate</Dropdown.Item> <Dropdown.Item icon={TrashIcon} variant="danger" kbd="⌘⌫">Delete</Dropdown.Item> </Dropdown.Menu></Dropdown>
Select one or many menu options.
<Dropdown> <Dropdown.Trigger> <Button iconTrailing={ChevronDownIcon}>Permissions</Button> </Dropdown.Trigger> <Dropdown.Menu> <Dropdown.Checkbox defaultChecked>Read</Dropdown.Checkbox> <Dropdown.Checkbox defaultChecked>Write</Dropdown.Checkbox> <Dropdown.Checkbox>Delete</Dropdown.Checkbox> </Dropdown.Menu></Dropdown>
Select a single menu option.
<Dropdown> <Dropdown.Trigger> <Button iconTrailing={ChevronDownIcon}>Sort by</Button> </Dropdown.Trigger> <Dropdown.Menu> <Dropdown.RadioGroup defaultValue="latest"> <Dropdown.Radio value="latest">Latest activity</Dropdown.Radio> <Dropdown.Radio value="created">Date created</Dropdown.Radio> <Dropdown.Radio value="popular">Most popular</Dropdown.Radio> </Dropdown.RadioGroup> </Dropdown.Menu></Dropdown>
Visually group related menu items with a separator line.
<Dropdown> <Dropdown.Trigger> <Button iconTrailing={ChevronDownIcon}>Options</Button> </Dropdown.Trigger> <Dropdown.Menu> <Dropdown.Item>View</Dropdown.Item> <Dropdown.Item>Transfer</Dropdown.Item> <Dropdown.Separator /> <Dropdown.Item>Publish</Dropdown.Item> <Dropdown.Item>Share</Dropdown.Item> <Dropdown.Separator /> <Dropdown.Item variant="danger">Delete</Dropdown.Item> </Dropdown.Menu></Dropdown>
Group options under headings to make them more discoverable.
<Dropdown> <Dropdown.Trigger> <Button iconTrailing={ChevronDownIcon}>Options</Button> </Dropdown.Trigger> <Dropdown.Menu> <Dropdown.Group heading="Account"> <Dropdown.Item>Profile</Dropdown.Item> <Dropdown.Item>Permissions</Dropdown.Item> </Dropdown.Group> <Dropdown.Group heading="Billing"> <Dropdown.Item>Transactions</Dropdown.Item> <Dropdown.Item>Payouts</Dropdown.Item> <Dropdown.Item>Refunds</Dropdown.Item> </Dropdown.Group> <Dropdown.Item>Logout</Dropdown.Item> </Dropdown.Menu></Dropdown>
Nest submenus for more condensed menus.
<Dropdown> <Dropdown.Trigger> <Button iconTrailing={ChevronDownIcon}>Options</Button> </Dropdown.Trigger> <Dropdown.Menu> <Dropdown.Submenu heading="Sort by"> <Dropdown.RadioGroup defaultValue="name"> <Dropdown.Radio value="name">Name</Dropdown.Radio> <Dropdown.Radio value="date">Date</Dropdown.Radio> <Dropdown.Radio value="popularity">Popularity</Dropdown.Radio> </Dropdown.RadioGroup> </Dropdown.Submenu> <Dropdown.Submenu heading="Filter"> <Dropdown.Checkbox defaultChecked>Draft</Dropdown.Checkbox> <Dropdown.Checkbox defaultChecked>Published</Dropdown.Checkbox> <Dropdown.Checkbox>Archived</Dropdown.Checkbox> </Dropdown.Submenu> <Dropdown.Separator /> <Dropdown.Item variant="danger">Delete</Dropdown.Item> </Dropdown.Menu></Dropdown>
Menus typically close when an item is clicked, however, you can add the keepOpen prop to the Dropdown.Menu component to keep it open.
<Dropdown> <Dropdown.Trigger> <Button iconTrailing={ChevronDownIcon}>Filter</Button> </Dropdown.Trigger> <Dropdown.Menu keepOpen> <Dropdown.Checkbox defaultChecked>Draft</Dropdown.Checkbox> <Dropdown.Checkbox defaultChecked>Published</Dropdown.Checkbox> <Dropdown.Checkbox>Archived</Dropdown.Checkbox> </Dropdown.Menu></Dropdown>
If you only want the menu to stay open for specific items, add keepOpen directly to Dropdown.Item, Dropdown.Checkbox, Dropdown.Radio, Dropdown.RadioGroup, or Dropdown.Submenu.
<Dropdown> <Dropdown.Trigger> <Button iconTrailing={ChevronDownIcon}>Filters</Button> </Dropdown.Trigger> <Dropdown.Menu> <Dropdown.Checkbox keepOpen defaultChecked>Draft</Dropdown.Checkbox> <Dropdown.Checkbox keepOpen defaultChecked>Published</Dropdown.Checkbox> <Dropdown.Checkbox keepOpen>Archived</Dropdown.Checkbox> <Dropdown.Separator /> <Dropdown.Item variant="danger">Clear</Dropdown.Item> </Dropdown.Menu></Dropdown>
|
Prop
|
Description
|
|---|---|
| position |
Position of the dropdown menu. Options: top, right, bottom (default), left.
|
| align |
Alignment of the dropdown menu. Options: start, center, end. Default: start.
|
| offset |
Offset in pixels from the trigger element. Default: 0.
|
| gap |
Gap in pixels between trigger and menu. Default: 5.
|
| hover |
If true, opens the menu on hover in addition to click. Default: false.
|
| disabled |
If true, prevents the trigger from opening the menu.
|
| open |
Controlled open state of the menu. Pair with onOpenChange.
|
| defaultOpen |
Initial open state of the menu when uncontrolled.
|
| onOpenChange |
Callback fired when the menu opens or closes, receiving the new open state and eventDetails, whose reason tells why.
|
|
Attribute
|
Description
|
|---|---|
| data-flux-dropdown |
Applied to the root element for styling and identification.
|
| data-open |
Applied to the dropdown and its trigger while the menu is open.
|
Wraps the element that opens the menu, such as a Flux Button or Profile, and merges the trigger's props into it. It adds no element of its own.
|
Prop
|
Description
|
|---|---|
| children |
One element that opens the menu, such as a Flux Button. It must forward its props and ref, as every Flux component does.
|
| render |
Base UI's form of the same, for those who prefer it: the element to render as the trigger, or a function that receives the props and returns one. With render, the children become that element's content.
|
A complex menu component that supports keyboard navigation, submenus, checkboxes, and radio buttons.
|
Prop
|
Description
|
|---|---|
| keepOpen |
Prevents the menu from closing when any item inside of it is clicked.
|
|
Attribute
|
Description
|
|---|---|
| data-flux-menu |
Applied to the root element for styling and identification.
|
|
Prop
|
Description
|
|---|---|
| href |
The URL to link to. When set, the item renders as an a tag. An in-app URL navigates through the link registered in FluxProvider, and with Inertia, a POST route such as logout() or method="post" renders a button.
|
| target |
Where the link opens, such as _blank. Pass it with href, as you would rel and download. A target other than _self or a download renders a plain a tag.
|
| render |
Element to render instead of the item (such as a router link with props href can't carry), with the item's props merged in.
|
| icon |
Icon to display at the start of the item: a component, such as PlusIcon from @fluxui-dev/react/icons, or an element, such as <img />, rendered as is.
|
| iconTrailing |
Icon to display at the end of the item: a component or an element.
|
| iconVariant |
Variant of the icon. Options: outline, solid, mini, micro.
|
| kbd |
Keyboard shortcut hint displayed at the end of the item.
|
| suffix |
Text displayed at the end of the item.
|
| variant |
Visual style of the item. Options: default, danger.
|
| disabled |
If true, prevents interaction with the menu item.
|
| keepOpen |
Prevents the menu from closing when this item is selected.
|
|
Attribute
|
Description
|
|---|---|
| data-flux-menu-item |
Applied to the root element for styling and identification.
|
| data-highlighted |
Applied when the item is highlighted by the pointer or keyboard.
|
| data-disabled |
Applied when the item is disabled.
|
|
Prop
|
Description
|
|---|---|
| heading |
Text displayed as the submenu heading.
|
| icon |
Icon to display at the start of the submenu: a component or an element.
|
| iconTrailing |
Icon to display at the end of the submenu, in place of the chevron: a component or an element.
|
| iconVariant |
Variant of the icon. Options: outline, solid, mini, micro.
|
| disabled |
If true, prevents the submenu from opening.
|
| keepOpen |
Prevents the submenu from closing when any item inside of it is selected.
|
|
CSS
|
Description
|
|---|---|
| className |
CSS classes applied to the submenu's menu (not its trigger item).
|
Groups related menu items between separators, with an optional heading.
|
Prop
|
Description
|
|---|---|
| heading |
Heading text displayed above the group's items.
|
Groups multiple Dropdown.Checkbox items into a single array of checked values.
|
Prop
|
Description
|
|---|---|
| value |
Controlled array of checked checkbox values.
|
| defaultValue |
Initial array of checked values when uncontrolled.
|
| onValueChange |
Callback fired with the new array of values and the toggled checkbox's eventDetails when a checkbox is toggled.
|
|
Prop
|
Description
|
|---|---|
| checked |
Controlled checked state of the checkbox.
|
| defaultChecked |
Initial checked state of the checkbox when uncontrolled.
|
| onCheckedChange |
Callback fired with the new checked state and eventDetails when the checkbox is toggled.
|
| value |
Value identifying the checkbox within a Dropdown.CheckboxGroup.
|
| label |
Label text displayed when the checkbox has no children.
|
| iconTrailing |
Icon to display at the end of the item: a component or an element.
|
| iconVariant |
Variant of the check mark and the trailing icon: outline, solid, mini, or micro. Default: mini.
|
| disabled |
If true, prevents interaction with the checkbox.
|
| keepOpen |
Prevents the menu from closing when this checkbox is selected.
|
|
Attribute
|
Description
|
|---|---|
| data-highlighted |
Applied when the checkbox is highlighted by the pointer or keyboard.
|
| data-checked |
Applied when the checkbox is checked.
|
|
Prop
|
Description
|
|---|---|
| value |
Controlled value of the selected radio item.
|
| defaultValue |
Initial selected value when uncontrolled.
|
| onValueChange |
Callback fired with the new value and eventDetails when a radio item is selected.
|
| keepOpen |
Prevents the menu from closing when any radio button in this group is selected.
|
|
Prop
|
Description
|
|---|---|
| value |
Value this radio selects in its Dropdown.RadioGroup. Required.
|
| label |
Label text displayed when the radio has no children.
|
| iconTrailing |
Icon to display at the end of the item: a component or an element.
|
| iconVariant |
Variant of the check mark and the trailing icon: outline, solid, mini, or micro. Default: mini.
|
| disabled |
If true, prevents interaction with the radio button.
|
| keepOpen |
Prevents the menu from closing when this radio button is selected.
|
|
Attribute
|
Description
|
|---|---|
| data-highlighted |
Applied when the radio button is highlighted by the pointer or keyboard.
|
| data-checked |
Applied when the radio button is selected.
|