When To Use
If there are too many operations to display, you can wrap them in a Dropdown. By clicking on the trigger, a dropdown menu should appear, which allows you to choose one option and execute relevant actions.
Use the `Dropdown` component with a `trigger` slot to define the toggle element. Inside, use `DropdownItem` and `DropdownItemDivider` to build the menu.
astro
---
import Dropdown from '@/components/navigation/Dropdown.astro';
import DropdownItem from '@/components/navigation/DropdownItem.astro';
import DropdownItemDivider from '@/components/navigation/DropdownItemDivider.astro';
import Button from '@/components/general/Button.astro';
---
<Dropdown placement="bottom-start">
<Button slot="trigger" variant="outline">Open Menu</Button>
<DropdownItem icon="User">Profile</DropdownItem>
<DropdownItem icon="Settings" shortcut="⌘S">Settings</DropdownItem>
<DropdownItemDivider />
<DropdownItem icon="LogOut" intent="danger">Logout</DropdownItem>
</Dropdown> astro
---
import Dropdown from '@/components/navigation/Dropdown.astro';
import DropdownItem from '@/components/navigation/DropdownItem.astro';
import DropdownItemDivider from '@/components/navigation/DropdownItemDivider.astro';
---
<Dropdown triggerType="contextmenu">
<div slot="trigger" class="flex h-32 w-64 items-center justify-center rounded-lg border-2 border-dashed border-zinc-300 bg-zinc-50 text-zinc-500 dark:border-zinc-700 dark:bg-zinc-800/50 dark:text-zinc-400">
Right click me
</div>
<DropdownItem icon="RefreshCw">Refresh</DropdownItem>
<DropdownItem icon="Link">Copy Link</DropdownItem>
<DropdownItemDivider />
<DropdownItem icon="Trash2" intent="danger">Delete</DropdownItem>
</Dropdown> Nested Submenus
You can create deep, cascading context menus by using the `submenu` slot inside a `DropdownItem`.
astro
---
import Dropdown from '@/components/navigation/Dropdown.astro';
import DropdownItem from '@/components/navigation/DropdownItem.astro';
import Button from '@/components/general/Button.astro';
---
<Dropdown placement="bottom-start">
<Button slot="trigger">Create New</Button>
<DropdownItem icon="FileText">Document</DropdownItem>
<DropdownItem icon="Folder">Folder</DropdownItem>
<DropdownItem icon="Share2">
Share
<div slot="submenu">
<DropdownItem icon="Mail">Email</DropdownItem>
<DropdownItem icon="Link">Copy Link</DropdownItem>
<DropdownItem icon="Users">
Social Media
<div slot="submenu">
<DropdownItem>Twitter</DropdownItem>
<DropdownItem>LinkedIn</DropdownItem>
</div>
</DropdownItem>
</div>
</DropdownItem>
</Dropdown> API Reference
Dropdown
| Property | Description | Type | Default |
|---|---|---|---|
| placement | Preferred placement of the dropdown relative to the trigger. | 'bottom-start' | 'bottom-end' | 'top-start' | 'top-end' | 'right-start' | 'left-start' | 'bottom-start' |
| triggerType | Event type that opens the menu. | 'click' | 'contextmenu' | 'click' |
| class | Custom classes for the dropdown content container. | string | - |
DropdownItem
| Property | Description | Type | Default |
|---|---|---|---|
| class | Custom classes for the item. | string | '-' |
| icon | Icon name to display to the left. | IconName | '-' |
| disabled | Disables the item. | boolean | false |
| href | URL to navigate to when clicked. | string | '-' |
| shortcut | Keyboard shortcut hint. | string | '-' |
| checked | Whether the item represents a checked state. | boolean | false |
| intent | Visual intent color. | 'default' | 'danger' | 'default' |