DropdownMenu
Collects secondary actions behind one trigger. Use when a screen has more actions than it can show.
partially-compliant
- Overview
- Props
- Figma
Usage
Trigger Types
ButtonTrigger
DropdownMenu.ButtonTrigger is the most common trigger. Use it when you have a text label. It accepts all regular Button props:
<DropdownMenu>
<DropdownMenu.ButtonTrigger size="sm" hasDropdownArrow>
Actions
</DropdownMenu.ButtonTrigger>
<DropdownMenu.Content>{/* Items... */}</DropdownMenu.Content>
</DropdownMenu>
IconButtonTrigger
DropdownMenu.IconButtonTrigger is for icon-only triggers. It accepts all IconButton props. Always provide an aria-label for accessibility:
<DropdownMenu>
<DropdownMenu.IconButtonTrigger icon="MoreVert" aria-label="Open actions menu" />
<DropdownMenu.Content>{/* Items... */}</DropdownMenu.Content>
</DropdownMenu>
SemanticButtonTrigger
DropdownMenu.SemanticButtonTrigger allows using a fully custom element as the trigger while maintaining accessibility. Useful when you need a completely custom trigger appearance:
<DropdownMenu>
<DropdownMenu.SemanticButtonTrigger>
<Box sx={{ padding: "$px8", backgroundColor: "$indigo50", borderRadius: "$px12" }}>
<HStack gap="$px4" sx={{ alignItems: "center" }}>
<Text size="$text200" weight="medium">
Custom trigger
</Text>
<Icon visual="ArrowDropdown" size="size16" />
</HStack>
</Box>
</DropdownMenu.SemanticButtonTrigger>
<DropdownMenu.Content>{/* Items... */}</DropdownMenu.Content>
</DropdownMenu>
Disabled items
Custom items
By default, DropdownMenu.Item renders a button. It's possible to render a different element instead. It's especially useful to render a link (or a Link from react-router-dom):
Complex items
Each items renders text by default. It's possible to pass a more complex element as a child instead:
Items onPress
It is possible to add an onPress prop to the DropdownMenu.Item component:
Inner scroll
It's possible to add a scroll to some port of the DropdownMenu:
Focusable elements
The DropdownMenu controls the focus of its children. It's especially important to ensure accessibility and keyboard navigation.
If you need to add a focusable element inside the DropdownMenu (e.g. a text input), you need to use the DropdownMenu.Focusable to ensure the focus is managed correctly.
<DropdownMenu>
<DropdownMenu.ButtonTrigger>{/* ... */}</DropdownMenu.ButtonTrigger>
<DropdownMenu.Content>
<DropdownMenu.Focusable>
<TextInput placeholder="Search" value={search} onChange={setSearch} />
</DropdownMenu.Focusable>
<Spacer size="$px4" />
<DropdownMenu.Item>Settings</DropdownMenu.Item>
{/* More items... */}
</DropdownMenu.Content>
</DropdownMenu>
Mobile
On mobile, DropdownMenu.Content will be displayed in a BottomSheet. Please note that the DropdownMenu must be controlled in order to work on mobile.
Playground
murray and murray/mobile.DropdownMenu props
| Name | Type | Default Value | Description | Usage count |
|---|---|---|---|---|
| children* | PopoverProps["children"] | |||
| disableFocus | PopoverProps["disableFocus"] | |||
| hoverable | PopoverProps["hoverable"] | |||
| keepChildrenMounted | PopoverProps["keepChildrenMounted"] | |||
| onOpenChange | PopoverProps["onOpenChange"] | |||
| open | PopoverProps["open"] | |||
| placement | PopoverProps["placement"] |