Docs
Dropdown Menu
Dropdown Menu
Displays a menu to the user — such as a set of actions or functions — triggered by a button.
Loading...
<script lang="ts">
import { Button } from "@/components/ui/button";
import * as DropdownMenu from "@/components/ui/dropdown-menu";
</script>
<DropdownMenu.Root>
<DropdownMenu.Trigger asChild let:builder>
<Button builders={[builder]} variant="outline">Open</Button>
</DropdownMenu.Trigger>
<DropdownMenu.Content class="w-56">
<DropdownMenu.Label>My Account</DropdownMenu.Label>
<DropdownMenu.Separator />
<DropdownMenu.Group>
<DropdownMenu.Item>
Profile
<DropdownMenu.Shortcut>⇧⌘P</DropdownMenu.Shortcut>
</DropdownMenu.Item>
<DropdownMenu.Item>
Billing
<DropdownMenu.Shortcut>⌘B</DropdownMenu.Shortcut>
</DropdownMenu.Item>
<DropdownMenu.Item>
Settings
<DropdownMenu.Shortcut>⌘S</DropdownMenu.Shortcut>
</DropdownMenu.Item>
<DropdownMenu.Item>
Keyboard shortcuts
<DropdownMenu.Shortcut>⌘K</DropdownMenu.Shortcut>
</DropdownMenu.Item>
</DropdownMenu.Group>
<DropdownMenu.Separator />
<DropdownMenu.Group>
<DropdownMenu.Item>Team</DropdownMenu.Item>
<DropdownMenu.Sub>
<DropdownMenu.SubTrigger>Invite users</DropdownMenu.SubTrigger>
<DropdownMenu.SubContent>
<DropdownMenu.Item>Email</DropdownMenu.Item>
<DropdownMenu.Item>Message</DropdownMenu.Item>
<DropdownMenu.Separator />
<DropdownMenu.Item>More...</DropdownMenu.Item>
</DropdownMenu.SubContent>
</DropdownMenu.Sub>
<DropdownMenu.Item>
New Team
<DropdownMenu.Shortcut>⌘+T</DropdownMenu.Shortcut>
</DropdownMenu.Item>
</DropdownMenu.Group>
<DropdownMenu.Separator />
<DropdownMenu.Item>GitHub</DropdownMenu.Item>
<DropdownMenu.Item>Support</DropdownMenu.Item>
<DropdownMenu.Item>API</DropdownMenu.Item>
<DropdownMenu.Separator />
<DropdownMenu.Item>
Log out
<DropdownMenu.Shortcut>⇧⌘Q</DropdownMenu.Shortcut>
</DropdownMenu.Item>
</DropdownMenu.Content>
</DropdownMenu.Root>
<script lang="ts">
import {
Cloud,
CreditCard,
Github,
Keyboard,
LifeBuoy,
LogOut,
Mail,
MessageSquare,
Plus,
PlusCircle,
Settings,
User,
UserPlus,
Users
} from "lucide-svelte";
import { Button } from "@/components/ui/button";
import * as DropdownMenu from "@/components/ui/dropdown-menu";
</script>
<DropdownMenu.Root>
<DropdownMenu.Trigger asChild let:builder>
<Button builders={[builder]} variant="outline">Open</Button>
</DropdownMenu.Trigger>
<DropdownMenu.Content class="w-56">
<DropdownMenu.Label>My Account</DropdownMenu.Label>
<DropdownMenu.Separator />
<DropdownMenu.Group>
<DropdownMenu.Item>
<User class="mr-2 h-4 w-4" />
<span>Profile</span>
<DropdownMenu.Shortcut>⇧⌘P</DropdownMenu.Shortcut>
</DropdownMenu.Item>
<DropdownMenu.Item>
<CreditCard class="mr-2 h-4 w-4" />
<span>Billing</span>
<DropdownMenu.Shortcut>⌘B</DropdownMenu.Shortcut>
</DropdownMenu.Item>
<DropdownMenu.Item>
<Settings class="mr-2 h-4 w-4" />
<span>Settings</span>
<DropdownMenu.Shortcut>⌘S</DropdownMenu.Shortcut>
</DropdownMenu.Item>
<DropdownMenu.Item>
<Keyboard class="mr-2 h-4 w-4" />
<span>Keyboard shortcuts</span>
<DropdownMenu.Shortcut>⌘K</DropdownMenu.Shortcut>
</DropdownMenu.Item>
</DropdownMenu.Group>
<DropdownMenu.Separator />
<DropdownMenu.Group>
<DropdownMenu.Item>
<Users class="mr-2 h-4 w-4" />
<span>Team</span>
</DropdownMenu.Item>
<DropdownMenu.Sub>
<DropdownMenu.SubTrigger>
<UserPlus class="mr-2 h-4 w-4" />
<span>Invite users</span>
</DropdownMenu.SubTrigger>
<DropdownMenu.SubContent>
<DropdownMenu.Item>
<Mail class="mr-2 h-4 w-4" />
<span>Email</span>
</DropdownMenu.Item>
<DropdownMenu.Item>
<MessageSquare class="mr-2 h-4 w-4" />
<span>Message</span>
</DropdownMenu.Item>
<DropdownMenu.Item>
<PlusCircle class="mr-2 h-4 w-4" />
<span>More...</span>
</DropdownMenu.Item>
</DropdownMenu.SubContent>
</DropdownMenu.Sub>
<DropdownMenu.Item>
<Plus class="mr-2 h-4 w-4" />
<span>New Team</span>
<DropdownMenu.Shortcut>⌘+T</DropdownMenu.Shortcut>
</DropdownMenu.Item>
</DropdownMenu.Group>
<DropdownMenu.Separator />
<DropdownMenu.Item>
<Github class="mr-2 h-4 w-4" />
<span>GitHub</span>
</DropdownMenu.Item>
<DropdownMenu.Item>
<LifeBuoy class="mr-2 h-4 w-4" />
<span>Support</span>
</DropdownMenu.Item>
<DropdownMenu.Item>
<Cloud class="mr-2 h-4 w-4" />
<span>API</span>
</DropdownMenu.Item>
<DropdownMenu.Separator />
<DropdownMenu.Item>
<LogOut class="mr-2 h-4 w-4" />
<span>Log out</span>
<DropdownMenu.Shortcut>⇧⌘Q</DropdownMenu.Shortcut>
</DropdownMenu.Item>
</DropdownMenu.Content>
</DropdownMenu.Root>
Installation
npx shadcn-svelte add dropdown-menu
Usage
<script lang="ts">
import * as DropdownMenu from "$components/ui/dropdown-menu";
</script>
<DropdownMenu.Root>
<DropdownMenu.Trigger>Open</DropdownMenu.Trigger>
<DropdownMenu.Content>
<DropdownMenu.Group>
<DropdownMenu.Label>My Account</DropdownMenu.Label>
<DropdownMenu.Separator />
<DropdownMenu.Item>Profile</DropdownMenu.Item>
<DropdownMenu.Item>Billing</DropdownMenu.Item>
<DropdownMenu.Item>Team</DropdownMenu.Item>
<DropdownMenu.Item>Subscription</DropdownMenu.Item>
</DropdownMenu.Group>
</DropdownMenu.Content>
</DropdownMenu.Root>
Examples
Checkboxes
Loading...
<script lang="ts">
import * as DropdownMenu from "@/components/ui/dropdown-menu";
import { Button } from "@/components/ui/button";
let showStatusBar = true;
let showActivityBar = false;
let showPanel = false;
</script>
<DropdownMenu.Root>
<DropdownMenu.Trigger asChild let:builder>
<Button variant="outline" builders={[builder]}>Open</Button>
</DropdownMenu.Trigger>
<DropdownMenu.Content class="w-56">
<DropdownMenu.Label>Appearance</DropdownMenu.Label>
<DropdownMenu.Separator />
<DropdownMenu.CheckboxItem bind:checked={showStatusBar}>
Status Bar
</DropdownMenu.CheckboxItem>
<DropdownMenu.CheckboxItem bind:checked={showActivityBar} disabled>
Activity Bar
</DropdownMenu.CheckboxItem>
<DropdownMenu.CheckboxItem bind:checked={showPanel}>
Panel
</DropdownMenu.CheckboxItem>
</DropdownMenu.Content>
</DropdownMenu.Root>
<script lang="ts">
import * as DropdownMenu from "@/components/ui/dropdown-menu";
import { Button } from "@/components/ui/button";
let showStatusBar = true;
let showActivityBar = false;
let showPanel = false;
</script>
<DropdownMenu.Root>
<DropdownMenu.Trigger asChild let:builder>
<Button variant="outline" builders={[builder]}>Open</Button>
</DropdownMenu.Trigger>
<DropdownMenu.Content class="w-56">
<DropdownMenu.Label>Appearance</DropdownMenu.Label>
<DropdownMenu.Separator />
<DropdownMenu.CheckboxItem bind:checked={showStatusBar}>
Status Bar
</DropdownMenu.CheckboxItem>
<DropdownMenu.CheckboxItem bind:checked={showActivityBar} disabled>
Activity Bar
</DropdownMenu.CheckboxItem>
<DropdownMenu.CheckboxItem bind:checked={showPanel}>
Panel
</DropdownMenu.CheckboxItem>
</DropdownMenu.Content>
</DropdownMenu.Root>
Radio Group
Loading...
<script lang="ts">
import * as DropdownMenu from "@/components/ui/dropdown-menu";
import { Button } from "@/components/ui/button";
let position = "bottom";
</script>
<DropdownMenu.Root>
<DropdownMenu.Trigger asChild let:builder>
<Button variant="outline" builders={[builder]}>Open</Button>
</DropdownMenu.Trigger>
<DropdownMenu.Content class="w-56">
<DropdownMenu.Label>Panel Position</DropdownMenu.Label>
<DropdownMenu.Separator />
<DropdownMenu.RadioGroup bind:value={position}>
<DropdownMenu.RadioItem value="top">Top</DropdownMenu.RadioItem>
<DropdownMenu.RadioItem value="bottom">Bottom</DropdownMenu.RadioItem>
<DropdownMenu.RadioItem value="right">Right</DropdownMenu.RadioItem>
</DropdownMenu.RadioGroup>
</DropdownMenu.Content>
</DropdownMenu.Root>
<script lang="ts">
import * as DropdownMenu from "@/components/ui/dropdown-menu";
import { Button } from "@/components/ui/button";
let position = "bottom";
</script>
<DropdownMenu.Root>
<DropdownMenu.Trigger asChild let:builder>
<Button variant="outline" builders={[builder]}>Open</Button>
</DropdownMenu.Trigger>
<DropdownMenu.Content class="w-56">
<DropdownMenu.Label>Panel Position</DropdownMenu.Label>
<DropdownMenu.Separator />
<DropdownMenu.RadioGroup bind:value={position}>
<DropdownMenu.RadioItem value="top">Top</DropdownMenu.RadioItem>
<DropdownMenu.RadioItem value="bottom">Bottom</DropdownMenu.RadioItem>
<DropdownMenu.RadioItem value="right">Right</DropdownMenu.RadioItem>
</DropdownMenu.RadioGroup>
</DropdownMenu.Content>
</DropdownMenu.Root>
On This Page