Popover
Show interactive details or a short hint by anchoring content to a trigger.
npx @swipeui/cli add popoverWhen to use it
- Small panels attached to a button, such as a share target picker or a quick setting.
- Explanations or controls that should appear next to what triggered them.
- Content that must stay on screen around the keyboard and safe areas.
When not to use it
- Use Menu for action lists.
- Use Bottom Sheet for larger content.
Installation
Run this from your app's root. If SwipeUI isn't set up yet, run npx @swipeui/cli init first; it sets up Uniwind, the theme tokens and the cn helper.
npx @swipeui/cli add popover- Adds
components/swipeui/overlay/placement.ts,components/swipeui/overlay/popover.tsxand 11 shared helpers. - Installs react-native-safe-area-context, react-native-reanimated, react-native-worklets, uniwind, clsx, tailwind-merge, expo-haptics, class-variance-authority, react-native-gesture-handler. In Expo apps it uses
npx expo installso versions match your SDK.
Usage
import { Popover } from '@/components/swipeui/overlay/popover';
<Popover triggerLabel="Trail details" title="Cedar Hollow" width={280}>
<TrailDetails route={route} />
</Popover>
<Popover triggerLabel="Route visibility" hint="Private routes are visible only to you." />A hint describes the trigger. It stays non-modal and supports touch hold and web hover or focus. Use the interactive form for buttons, headings or longer content. Pass anchor and returnFocusRef when a caller owns the trigger.
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
triggerLabel | | — | Trigger label, spoken by screen readers and shown when there is no custom trigger. |
trigger? | | | Custom trigger content, such as an icon; |
anchor? | | | Your own trigger, such as a field, drawn without Popover's pressable: Popover only anchors to it, and you open it with |
returnFocusRef? | | | Where focus returns when the panel closes. |
initialFocusRef? | | | What takes focus when the panel opens, such as the chosen row of a list. |
scrollRef? | | — | The panel's scroll view, for scrolling a chosen row into sight. |
triggerClassName? | | | Classes for the trigger pressable, replacing its default padding. |
title? | | — | Heading and initial modal focus. |
hint? | | — | Short non-interactive help text. Enables hint behavior when supplied. |
messages? | | — | Localize the close action for an interactive popover. |
showTitle? | | | Shows the title; when hidden it still names the panel for screen readers. |
closeButton? | | | The close button: always, only while a screen reader is on, or never. |
closeButtonStyle? | | | Use an accessible corner icon or a text action. |
density? | | | Panel spacing: roomy, or tight for menus. |
align? | | | Which edge of the trigger the panel lines up with. |
side? | | | Prefer below the trigger and shrink to available room, or flip automatically. |
pointer? | | — | Draw a pointer toward the trigger with an explicit side. |
clearBackdrop? | | — | Keep the background visible while the popover is open. |
maxContentHeight? | | | Maximum panel height before scrolling. |
triggerMotion? | | | Trigger-only press character, independent of the panel. |
onViewportChange? | | | Reports the placed, clipped window viewport; null while closed or unmeasured. |
children? | | — | Body/independent controls. |
open? | | — | Controlled visibility. |
defaultOpen? | | | Initial visibility. |
onOpenChange? | | — | Reports visibility intent. |
activation? | | | Trigger convention. |
modal? | | | Modal focus behavior. |
closeLabel? | | | Close action label. |
width? | | | Preferred width, or |
disabled? | | — | Disable opening. |
haptics? | | — | Press feedback. |
motion? | | — | Shared overlay/press character. |
className? | | — | Trigger wrapper classes. |
presentation? | | | Keep content in this scope's window for held gestures, or use a native modal window. |
testID? | | — | Root identifier. |
Use side="top", "bottom", "left", or "right" to choose a preferred edge, and choose align="start", "center", or "end" independently. Explicit sides keep the panel inside the available screen and may flip when space runs out. Set pointer to draw a marker toward the trigger. Choose closeButtonStyle="icon" for a compact corner action.
Behavior and gestures
- Tap the trigger (or long-press) to open a panel next to it.
- The panel flips above or below and stays inside the screen, the safe area and above the keyboard.
- Tap Close or outside to dismiss it.
- With a screen reader on, a single activation opens it even in long-press mode.
- trigger replaces the text trigger with custom content, such as an icon, while triggerLabel still names it; triggerClassName replaces its padding.
- showTitle, closeButton ('always', 'screen-reader' or 'never'), density ('comfortable' or 'compact') and align ('start', 'end' or 'auto') shape the panel; auto lines it up with the trigger's end edge when the trigger is in the end half of the screen.
- Hold the trigger on touch, or hover or focus it on the web, to read a non-modal hint.
Accessibility
- Focus moves to the panel title and returns to the trigger when it closes.
- In modal mode, focus stays inside until it closes.
- The trigger reports expanded state and offers an activate action.
Motion
- Uses the
pressandoverlaymotion roles, so it follows your app's feel. Passmotionto tune this one instance. - Opens with the overlay role; Reduce Motion fades.
Performance
- Measures its trigger once per opening and on rotation or keyboard changes.
Notes for AI
- Wrap the app in OverlayProvider; keep the panel short.
- Use hint for short non-interactive help instead of a full interactive panel.
Compatibility
| Runs on | Supported |
|---|---|
| Expo SDK 57 | Yes |
| Expo SDK 58 | Yes |
| React Native CLI (with Expo modules) | Yes |
| Expo Go | Yes |
| iOS | Yes |
| Android | Yes |
This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.