ZUI

Search documentation

Find a page or a heading.

Popover

A floating panel beside the control that opened it.

Installation

bash

The CLI writes components/ui/popover.tsx, lib/motion.ts and lib/overlay.ts, installs Text and Utils, and adds @rn-primitives/popover, @rn-primitives/portal, 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

Popover

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

Without open the Popover holds its own state, starting from defaultOpen. With it, the Popover follows open, and a press on the trigger, outside the content or the back button only reports the change it asks for through onOpenChange. Hold the state to close the Popover from inside it, such as from a form's Save button:

tsx

PopoverTrigger

Takes every prop of React Native's Pressable. A press opens the Popover, and another closes it. Pass asChild to make a Button do it. Focus returns to the trigger when the Popover closes.

PopoverContent

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

side is the side of the trigger the panel opens on, sideOffset its gap from the trigger in px, and align lines it up with the trigger's start, centre or end, moved along by alignOffset. The panel is 18rem wide; pass a width class to change it. It is a dialog named by its PopoverTitle, and accessibility focus moves into it as it opens. A press outside it, the Android back button, the iOS escape gesture (a two-finger Z) and Escape on the web close it. It fades in while growing from 95% and sliding 0.5rem away from the trigger over 100ms, and out the same way. When the system asks for reduced motion it appears and goes at once.

PopoverHeader, PopoverTitle and PopoverDescription

PopoverHeader takes every prop of React Native's View, and the other two every prop of Text. The title is a heading.

Differences from upstream

  • Upstream's render prop becomes asChild, as on every native item.
  • On a device the panel opens above or below its trigger, so left and right open it below. It is kept on the screen but not moved to the other side when there is no room. The web places it on any side, and flips it.
  • On iOS, VoiceOver does not read aria-labelledby, so the panel 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.
  • 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.