Menu checkbox item
In code: MenuCheckboxItem
A menu row that is on or off: "Show weekends"
Preview
Use
The code of the preview above
import { useState } from 'react';
import { Button, Calendar, Menu, MenuCheckboxItem, MenuContent, MenuTrigger } from '@/components/ui';
import { Calendar } from 'lucide-react';
function ShowMenuDemo() {
const [weekends, setWeekends] = useState(true);
const [cancelled, setCancelled] = useState(false);
return (
<Menu>
<MenuTrigger render={<Button />}><Calendar />Show</MenuTrigger>
<MenuContent>
<MenuCheckboxItem checked={weekends} onCheckedChange={(on: boolean) => setWeekends(on)}>Show weekends</MenuCheckboxItem>
<MenuCheckboxItem checked={cancelled} onCheckedChange={(on: boolean) => setCancelled(on)}>Show cancelled bookings</MenuCheckboxItem>
</MenuContent>
</Menu>
);
}Options
| Option | Type | What it does |
|---|---|---|
children | ReactNode | What goes inside. |
className | string | More classes on the outer element, for layout around it (margins, grid placement), not to restyle it. |
value | string | The current value, when your state holds it (controlled); use with onValueChange. |
It also takes the 281 attributes of the element or UI SDK part it draws: className, aria-label, events and the rest.
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.cssIn the examples
Small screens made with it and the rest of the kit. They work: click, type and choose in them.
Grid on100%
On top of the page: states, do and don’t
Menu rows that tick: "Show weekends", "Sort by".
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.