Radix UI Dropdown Menu Checkbox Not Working — Fix Checked State
In this fix, you'll learn how to use checkable items in Radix UI dropdown menus. This matters for multi-select menu items, and appears in filter menus and settings dropdowns.
The Problem
The following code demonstrates the typical mistake:
<DropdownMenuCheckboxItem>
Show details
</DropdownMenuCheckboxItem>
// Checkbox never shows as checked
The Fix
Here is the corrected version:
const [showDetails, setShowDetails] = useState(true);
<DropdownMenuCheckboxItem
checked={showDetails}
onCheckedChange={setShowDetails}
>
<DropdownMenuItemIndicator>
<Check className="h-4 w-4" />
</DropdownMenuItemIndicator>
Show details
</DropdownMenuCheckboxItem>
// Checkbox toggles checked state correctly
Prevention
- Use checked and onCheckedChange for controlled checkbox items.
- Add DropdownMenuItemIndicator to show a check icon when checked.
- For radio groups, use DropdownMenuRadioGroup and DropdownMenuRadioItem.
- The checked state persists within the menu session unless managed externally.
- Use onCheckedChange handler to persist the setting (localStorage, state).
Common Mistakes with ui dropdown check
- Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
- Using
returnto exit a function early instead of wrapping a pure value in the monad - Mixing let bindings with <- bindings in do notation, producing type errors
These mistakes appear frequently in real-world RADIX code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro