@radix-ui/react-dialog
Fully accessible, unstyled dialog (modal) primitive for React — WAI-ARIA compliant with focus trapping, scroll locking, and composable parts.
@radix-ui/react-dialog
ReactFully accessible, unstyled dialog (modal) primitive for React — WAI-ARIA compliant with focus trapping, scroll locking, and composable parts.
Fit
Bundle (gzip)
12.6 kB
37.9 kB raw
Install size includes transitive dependencies. Bundle size is gzipped browser payload.
Freshness
The Problem
Building an accessible modal from scratch requires managing focus traps, aria-modal, scroll locking, portal rendering, and keyboard dismissal. Getting all of these right simultaneously is surprisingly complex.
What It Does
Radix Dialog handles all accessibility concerns out of the box — focus is trapped inside, scroll is locked, Escape closes it, and all ARIA attributes are correct. You provide only the visual styling via your own CSS or Tailwind classes.
Installation
npm install @radix-ui/react-dialogUsage Example
import * as Dialog from '@radix-ui/react-dialog';
export function ConfirmDialog() {
return (
<Dialog.Root>
<Dialog.Trigger asChild>
<button>Delete Account</button>
</Dialog.Trigger>
<Dialog.Portal>
<Dialog.Overlay className="fixed inset-0 bg-black/50" />
<Dialog.Content className="fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 bg-white p-6 rounded-lg shadow-xl">
<Dialog.Title>Are you sure?</Dialog.Title>
<Dialog.Description>This action cannot be undone.</Dialog.Description>
<Dialog.Close asChild>
<button>Cancel</button>
</Dialog.Close>
</Dialog.Content>
</Dialog.Portal>
</Dialog.Root>
);
}Related packages
Fast, composable command palette for React — keyboard-driven search UI with fuzzy filtering and accessible markup out of the box.
@dnd-kit/coreReactModern, accessible drag-and-drop toolkit for React — fully customizable with keyboard support, collision detection, and zero dependencies.
embla-carousel-reactReactLightweight, extensible carousel library for React — smooth scrolling, touch/mouse drag, and full CSS control without prescribing markup.
flagsReactProvider-agnostic feature flags SDK for Next.js and React — toggle features without redeploying.
framer-motionReactProduction-ready declarative animation library for React — gestures, layout animations, and scroll-driven effects with a clean API.