Components
Context menu
A menu that opens where the pointer is, on a right-click or a long press.
Right-click or long-press this role
import { Bookmark, Copy, ExternalLink, X } from 'lucide-react'
import {
ContextMenu,
ContextMenuContent,
ContextMenuItem,
ContextMenuSeparator,
ContextMenuTrigger,
} from '@dex/shared/components/context-menu'
export function ContextMenuDefault() {
return (
<ContextMenu>
<ContextMenuTrigger className="flex h-32 w-72 items-center justify-center rounded-xl bg-card text-sm text-muted-foreground shadow-xs select-none">
Right-click or long-press this role
</ContextMenuTrigger>
<ContextMenuContent className="w-56">
<ContextMenuItem>
<Bookmark /> Save for later
</ContextMenuItem>
<ContextMenuItem>
<ExternalLink /> Open in a new tab
</ContextMenuItem>
<ContextMenuItem>
<Copy /> Copy link
</ContextMenuItem>
<ContextMenuSeparator />
<ContextMenuItem variant="destructive">
<X /> Not for me
</ContextMenuItem>
</ContextMenuContent>
</ContextMenu>
)
}
With a choice
Radio and checkbox items work as they do in the dropdown menu.
Your matchesSorted by best match
'use client'
import { useState } from 'react'
import {
ContextMenu,
ContextMenuContent,
ContextMenuLabel,
ContextMenuRadioGroup,
ContextMenuRadioItem,
ContextMenuTrigger,
} from '@dex/shared/components/context-menu'
const SORTS = ['Best match', 'Newest', 'Highest salary']
export function ContextMenuRadioItems() {
const [sort, setSort] = useState(SORTS[0])
return (
<ContextMenu>
<ContextMenuTrigger className="flex h-32 w-72 flex-col items-center justify-center gap-1 rounded-xl bg-card text-sm shadow-xs select-none">
<span>Your matches</span>
<span className="text-muted-foreground">Sorted by {sort.toLowerCase()}</span>
</ContextMenuTrigger>
<ContextMenuContent className="w-48">
<ContextMenuRadioGroup value={sort} onValueChange={setSort}>
<ContextMenuLabel>Sort by</ContextMenuLabel>
{SORTS.map((option) => (
<ContextMenuRadioItem key={option} value={option}>
{option}
</ContextMenuRadioItem>
))}
</ContextMenuRadioGroup>
</ContextMenuContent>
</ContextMenu>
)
}
- Nothing on the page shows a context menu is there, and a touch screen without long press never opens it. So it only offers shortcuts to things the page already does elsewhere, or small extras such as copying the logo, never the only way to do something.
- Keep it short: the few things someone is likely to want from that spot, most likely first.
- Its items, separators, labels and choices are the dropdown menu's, so the two look the same. Follow the dropdown menu's rules for them.
- A destructive item goes last, after a separator.
- Right-click the logo at the top of the sidebar to see one in use.