Radix UI Dialog Close Not Working — Fix Close Button
DodaTech
Updated 2026-06-24
1 min read
In this fix, you'll learn how to properly close Radix UI Dialogs. This matters for modal dismiss behavior, and appears in confirmation dialogs and forms.
The Problem
The following code demonstrates the typical mistake:
<Dialog>
<DialogTrigger>Open</DialogTrigger>
<DialogContent>
<p>Content</p>
<button onClick={() => {/* manually close */}}>Close</button>
</DialogContent>
</Dialog>
// Close button doesn't close the dialog properly
The Fix
Here is the corrected version:
<Dialog>
<DialogTrigger asChild>
<Button>Open</Button>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Title</DialogTitle>
</DialogHeader>
<p>Content here</p>
<DialogFooter>
<DialogClose asChild>
<Button variant="outline">Close</Button>
</DialogClose>
</DialogFooter>
</DialogContent>
</Dialog>
// Dialog closes correctly with Close button
Prevention
- Use the DialogClose component for close buttons inside dialogs.
- DialogClose automatically calls the close handler and respects Escape key.
- Use asChild when DialogClose wraps a styled Button component.
- DialogClose can be placed anywhere inside DialogContent.
- Escape key closes the dialog by default (Radix handles this).
Common Mistakes with ui dialog close
- 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
- Overlapping type class instances that cause GHC to reject the program with ambiguous dispatch 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
← Previous
Radix UI Context Menu Not Working — Fix Right-Click
Next →
Radix UI Dropdown Menu Checkbox Not Working — Fix Checked State
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro