Submenu
In code: MenuSub
A menu inside a menu: a row that opens more rows beside it. Put a <MenuSubTrigger> and a <MenuSubContent> inside, and place it among the menu's items.
Preview
Use
The code of the preview above
import {
Button,
Menu,
MenuContent,
MenuItem,
MenuSeparator,
MenuSub,
MenuSubContent,
MenuSubTrigger,
MenuTrigger,
toast,
} from '@/components/ui';
import { Download, Ellipsis, Mail, Trash2 } from 'lucide-react';
<Menu onAction={(value) => toast.show({ title: String(value) })}>
<MenuTrigger render={<Button icon aria-label="Actions for invoice 0412" />}><Ellipsis /></MenuTrigger>
<MenuContent>
<MenuItem value="Invoice 0412 sent again"><Mail />Send again</MenuItem>
<MenuSub>
<MenuSubTrigger><Download />Export</MenuSubTrigger>
<MenuSubContent>
<MenuItem value="Exported as PDF">PDF</MenuItem>
<MenuItem value="Exported as CSV">CSV</MenuItem>
</MenuSubContent>
</MenuSub>
<MenuSeparator />
<MenuItem value="Invoice 0412 deleted" danger><Trash2 />Delete</MenuItem>
</MenuContent>
</Menu>Options
No options of its own.
It also takes the 9 attributes of the element or UI SDK part it draws: className, aria-label, events and the rest.
Parts
What goes inside one.
Without React
With the CSS in parts (/ui/css/), it needs these, besides the ones every page loads:
components/button.csscomponents/popups.csscomponents/icons.csscomponents/menu-items-tick.csscomponents/prose.cssparts/listbox.cssparts/menubar.cssOn top of the page: states, do and don’t
A menu inside a menu: "Export" with its formats.
States. Closed, opening (fades and rises), open, closing (fades before what it changed appears: afterClose). While open, focus is inside and Escape closes it; when it closes, focus goes back to what opened it.
Do
- Name every dialog, drawer and popover (
DialogTitle,DrawerTitle, oraria-label). - Use
AlertDialogfor anything that cannot be undone, with the action named on its button ("Delete 3 files"). - Use a
Draweron a phone for what aPopoverdoes on a computer.
Don't
- Don't open a dialog from a dialog; change what the open one shows instead.
- Don't put the only way to do something in a right-click menu or a tooltip.
- Don't use a toast for something the person must not miss: that is an
Alerton the page.