- Label
- Icon label
- Field
- Form
- Frontmatter form
- Questionnaire
- Input
- Input group
- Input OTP
- Password input
- Password strength
- Code input
- Number field
- Tag input
- Textarea
- Checkbox
- Radio group
- Language toggle group
- Emoji appearance toggle group
- Emoji picker
- Avatar picker
- AI provider picker
- Select
- Native select
- Combobox
- Language combobox
- Slider
- Calendar
- Switch
- Alert
- Avatar
- Badge
- Card
- AI provider card
- Model info card
- Model list
- Empty
- Item
- Tree item
- File tree
- Icon media
- File type icon
- Font preview
- Image preview
- Kbd
- Table
- Data table
- Data table column header
- Chart
- Code Block
- Code card
- Markdown view
- Attachment
- Bubble
- Marker
- Message
- Chat message
- Chat suggestion item
- Message scroller
- Trace
- Progress
- Spinner
- Sonner
- Toast
- Unsaved changes toolbar
- Unsaved indicator
- Status indicator
- Permission card
- Separator
- Skeleton
- Animated grid pattern
- Meteors
Installation#
pnpm dlx shadcn@latest add @zui/popoverThe 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#
import { Button } from '@/components/ui/button';
import {
Popover,
PopoverContent,
PopoverDescription,
PopoverHeader,
PopoverTitle,
PopoverTrigger,
} from '@/components/ui/popover';
import { Text } from '@/components/ui/text';<Popover>
<PopoverTrigger asChild>
<Button variant="outline">
<Text>Open popover</Text>
</Button>
</PopoverTrigger>
<PopoverContent>
<PopoverHeader>
<PopoverTitle>Dimensions</PopoverTitle>
<PopoverDescription>Set the dimensions for the layer.</PopoverDescription>
</PopoverHeader>
</PopoverContent>
</Popover>API reference#
Popover#
Takes every prop of React Native's View, plus:
| Prop | Type | Default |
|---|---|---|
open | boolean | - |
defaultOpen | boolean | false |
onOpenChange | (open: boolean) => void | - |
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:
const [open, setOpen] = useState(false);
<Popover open={open} onOpenChange={setOpen}>
<PopoverTrigger asChild>
<Button variant="outline">
<Text>Rename</Text>
</Button>
</PopoverTrigger>
<PopoverContent>
{/* the form's fields */}
<Button onPress={() => setOpen(false)}>
<Text>Save</Text>
</Button>
</PopoverContent>
</Popover>;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:
| Prop | Type | Default |
|---|---|---|
side | 'top' | 'right' | 'bottom' | 'left' | 'bottom' |
sideOffset | number | 4 |
align | 'start' | 'center' | 'end' | 'center' |
alignOffset | number | 0 |
portalHost | string | - |
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
renderprop becomesasChild, as on every native item. - On a device the panel opens above or below its trigger, so
leftandrightopen 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.
portalHostis added, for an app that draws overlays into aPortalHostof its own.