Components
Dropdown menu
A short list of actions behind one button, such as what the host can do to a member of the room.
Leo
import * as DropdownMenu from "@sideby/ui/dropdown-menu";
import { buttonVariants } from "@sideby/ui/button";
import Ellipsis from "@lucide/svelte/icons/ellipsis";
<DropdownMenu.Root>
<DropdownMenu.Trigger class={buttonVariants({ variant: "ghost", size: "icon-sm" })} aria-label="Actions for Leo">
<Ellipsis aria-hidden="true" />
</DropdownMenu.Trigger>
<DropdownMenu.Content align="end">
<DropdownMenu.Group>
<DropdownMenu.GroupHeading>Leo</DropdownMenu.GroupHeading>
<DropdownMenu.Item onSelect={() => makeHost(leo)}>Make host</DropdownMenu.Item>
<DropdownMenu.Item variant="destructive" onSelect={() => kick(leo)}>Kick from room</DropdownMenu.Item>
</DropdownMenu.Group>
</DropdownMenu.Content>
</DropdownMenu.Root> When to use it
Use a dropdown menu for a handful of actions on one thing, when showing them all as buttons would crowd the screen: what the host can do to a member, what you can do with a room link. Two to five items is the sweet spot.
- Only actions. The menu is trimmed to items, groups with a heading, and separators. For picking a value, use a select.
- Confirm what cannot be undone. If an item ends something for someone else, open an alert dialog from it before acting.
- Essential actions stay visible. A menu hides its items until it opens, so the one action everyone needs belongs on the page as a button.
A member list
Every trigger names whose actions it holds, so a screen reader user moving down the list hears “Actions for Mia”, “Actions for Leo” and so on. A long name truncates in the heading instead of stretching the menu.
- Mia
- Leo
- Bartholomew Featherstonehaugh-Smythe
import { buttonVariants } from "@sideby/ui/button";
import * as DropdownMenu from "@sideby/ui/dropdown-menu";
import Ellipsis from "@lucide/svelte/icons/ellipsis";
<ul class="flex flex-col gap-2">
{#each members as name}
<li class="flex items-center justify-between gap-3">
<span class="min-w-0 truncate">{name}</span>
<DropdownMenu.Root>
<DropdownMenu.Trigger
class={buttonVariants({ variant: "ghost", size: "icon-sm" })}
aria-label={`Actions for ${name}`}
>
<Ellipsis aria-hidden="true" />
</DropdownMenu.Trigger>
<DropdownMenu.Content align="end">
<DropdownMenu.Group>
<DropdownMenu.GroupHeading>{name}</DropdownMenu.GroupHeading>
<DropdownMenu.Item>Make host</DropdownMenu.Item>
<DropdownMenu.Separator />
<DropdownMenu.Item variant="destructive">Kick from room</DropdownMenu.Item>
</DropdownMenu.Group>
</DropdownMenu.Content>
</DropdownMenu.Root>
</li>
{/each}
</ul> Parts
DropdownMenu.Rootholds the open state.DropdownMenu.Triggeropens it; style it withbuttonVariantsand give an icon trigger anaria-label.DropdownMenu.Contentportals the list to the end of the page.alignsets which edge lines up with the trigger (startby default).DropdownMenu.GroupandDropdownMenu.GroupHeadinggroup related items under a name in the label voice.DropdownMenu.Itemruns its action inonSelect.variant="destructive"colors the label for actions that remove or end something.DropdownMenu.Separatoris a hairline between groups.
Keyboard
- Enter, Space or Down Arrow on the trigger opens the menu and moves focus into it.
- Up and Down Arrow move between items. Home and End jump to the first and last.
- Typing a letter jumps to the next item that starts with it: “k” goes to “Kick from room”.
- Enter or Space runs the highlighted item and closes the menu.
- Escape closes the menu and returns focus to the trigger.
- Tab closes the menu and moves on to the next control after the trigger.
Accessibility
- Bits UI owns the behaviour: the
menuandmenuitemroles, roving focus, typeahead, Escape and focus return. Do not rebuild them. - The trigger names whose actions they are. “Actions for Leo”, never just “More” or “Options”, because a list of members has many triggers.
- Color is never the only cue. The destructive item is colored, and its words say exactly what happens.
- Menu labels render as text, so a member’s name cannot inject markup.
- On touch screens the menu opens on tap, and every item is at least 36px tall.
Copy
- Items are verbs: “Make host”, “Copy link”, “Kick from room”. Sentence case, no full stop.
- Destructive items say exactly what happens. “Kick from room”, not “Remove” or “Manage”.
- The heading is the thing the actions apply to, usually a name, so the person can check they opened the right menu.