ZUI

Search documentation

Find a page or a heading.

Dialog

A window over the screen that the person deals with before going back to it.

Installation

bash

The CLI writes components/ui/dialog.tsx, lib/motion.ts and lib/overlay.ts, installs Button, Icon, Text and Utils, and adds @rn-primitives/dialog, @rn-primitives/portal, lucide-react-native, react-native-reanimated and react-native-worklets. The content draws in the app's PortalHost; see Add a portal host. Without one it draws nothing, and logs an error saying so while the app is in development.

Usage

tsx
tsx

API reference

Dialog

Takes every prop of React Native's View, plus open, defaultOpen and onOpenChange(open). Without open the Dialog holds its own state, starting from defaultOpen.

DialogTrigger

Takes every prop of React Native's Pressable. Pressing it opens the Dialog. Pass asChild to make a Button the trigger. Focus returns to it when the Dialog closes.

DialogContent

Takes every prop of React Native's View, plus:

The content is centred over a dimmed overlay, 1rem in from the sides of the screen. It is a modal dialog named by its DialogTitle. Accessibility focus moves into it as it opens. A press on the overlay, the Android back button, the iOS escape gesture (a two-finger Z) and Escape on the web close it. showCloseButton draws a ghost button named Close in the top right corner. portalHost names the PortalHost to draw in when it is not the app's own.

VoiceOver stays inside the dialog while it is open. TalkBack does once the app hides its screens from screen readers while an overlay is shown, as Add a portal host shows; the web hides the rest of the page itself.

It fades in and zooms from 95% over 100ms, and out the same way. When the system asks for reduced motion it appears and goes at once.

DialogHeader and DialogFooter

Take every prop of React Native's View. The footer stacks its children with the first at the bottom. Put Cancel first so the main action sits on top. showCloseButton on the footer adds an outline Close button.

DialogTitle and DialogDescription

Take every prop of Text. The title is a heading.

DialogClose, DialogOverlay and DialogPortal

DialogClose closes the Dialog when pressed; pass asChild to make a Button do it. DialogContent already draws a DialogOverlay inside a DialogPortal, so you only need them to build content of your own.

Differences from upstream

  • Upstream's render prop becomes asChild, as on every native item.
  • On iOS, VoiceOver does not read aria-labelledby, so the dialog is not announced by its title's name there. Focus moves into the content, where the title is the first thing read. Android and the web read the name.
  • The footer always stacks its buttons. Upstream sets them in a row from the sm breakpoint, which a phone held upright does not reach.
  • Upstream widens the content to max-w-md from sm and blurs the screen behind the overlay. A phone is narrower than sm, and React Native has no backdrop blur.
  • Upstream's animation runs whatever the system's motion setting. The native one is skipped when the system asks for reduced motion.
  • portalHost is added, for an app that draws overlays into a PortalHost of its own.