import { Button, Popover, Text } from "@vortexlabs/vortex-native";
export const PopoverEstimateExample = () => (
<Popover>
<Popover.Trigger>
{({ onPress, "aria-expanded": expanded }) => (
<Button onPress={onPress} attributes={{ "aria-expanded": expanded }}>Delivery estimate</Button>
)}
</Popover.Trigger>
<Popover.Content ariaLabel="Delivery estimate">
<Text>Arrives in two to three days.</Text>
</Popover.Content>
</Popover>
);Features
- Opens as a sheet on small screens and beside the trigger from the sm breakpoint.
- Supports press and long-press triggers, controlled visibility, and alternate placements.
Anatomy
<Popover>
<Popover.Trigger>
{({ onPress }) => <Button onPress={onPress}>Open</Button>}
</Popover.Trigger>
<Popover.Content />
</Popover>Position
Use position to place floating content relative to the trigger. Set presentation="floating" to use that position on phones too.
import { Button, Popover, Text } from "@vortexlabs/vortex-native";
export const PopoverPlacementExample = () => (
<Popover presentation="floating" position="top-start">
<Popover.Trigger>
{({ onPress, "aria-expanded": expanded }) => (
<Button onPress={onPress} attributes={{ "aria-expanded": expanded }}>Show estimate</Button>
)}
</Popover.Trigger>
<Popover.Content ariaLabel="Delivery estimate">
<Text>Arrives on Friday.</Text>
</Popover.Content>
</Popover>
);Presentation
Use presentation="sheet" for a panel that opens from the bottom at every breakpoint.
import { Button, Popover, Text } from "@vortexlabs/vortex-native";
export const PopoverSheetExample = () => (
<Popover presentation="sheet" grabberAriaLabel="Close delivery window">
<Popover.Trigger>
{({ onPress, "aria-expanded": expanded }) => (
<Button onPress={onPress} attributes={{ "aria-expanded": expanded }}>Delivery window</Button>
)}
</Popover.Trigger>
<Popover.Content ariaLabel="Delivery window">
<Text>Deliveries arrive between 9 am and 5 pm.</Text>
</Popover.Content>
</Popover>
);Padding
Set padding to adjust the floating panel’s inset. For a sheet, use none to remove the default padding.
<Popover presentation="floating" padding="xs">
<Popover.Trigger>
{({ onPress, "aria-expanded": expanded }) => (
<Button onPress={onPress} attributes={{ "aria-expanded": expanded }}>Pickup counter</Button>
)}
</Popover.Trigger>
<Popover.Content ariaLabel="Pickup details">
<Text>Counter 4, ground floor.</Text>
</Popover.Content>
</Popover>Width
Use width="trigger" to match the floating panel to its trigger.
<Popover presentation="floating" width="trigger">
<Popover.Trigger>
{({ onPress, "aria-expanded": expanded }) => (
<Button onPress={onPress} attributes={{ "aria-expanded": expanded }}>View pickup instructions</Button>
)}
</Popover.Trigger>
<Popover.Content ariaLabel="Pickup details">
<Text>Bring your order number.</Text>
</Popover.Content>
</Popover>Triggers
Use triggerType="long-press" to open the panel on a press and hold. Forward the accessibility actions to the button.
<Popover presentation="floating" triggerType="long-press">
<Popover.Trigger>
{({ onLongPress, disabled, ...attributes }) => (
<Button onLongPress={onLongPress} disabled={disabled} attributes={attributes}>Hold for pickup details</Button>
)}
</Popover.Trigger>
<Popover.Content ariaLabel="Pickup details">
<Text>Collect your order before 5 pm.</Text>
</Popover.Content>
</Popover>Controlled Visibility
Set active when an action inside the panel also needs to close it. Update the same state in onOpen and onClose.
import { Button, Popover } from "@vortexlabs/vortex-native";
import { useState } from "react";
export const DeliveryUpdates = () => {
const [open, setOpen] = useState(false);
const [subscribed, setSubscribed] = useState(false);
return (
<Popover active={open} onOpen={() => setOpen(true)} onClose={() => setOpen(false)}>
<Popover.Trigger>
{({ onPress, "aria-expanded": expanded }) => (
<Button onPress={onPress} attributes={{ "aria-expanded": expanded }}>
{subscribed ? "Manage updates" : "Delivery updates"}
</Button>
)}
</Popover.Trigger>
<Popover.Content ariaLabel="Delivery updates">
<Button onPress={() => { setSubscribed(!subscribed); setOpen(false); }}>
{subscribed ? "Stop updates" : "Notify me"}
</Button>
</Popover.Content>
</Popover>
);
};Initial Focus
Set initialFocusRef to the element a screen reader should announce when the panel opens.
import { Button, Popover, Text } from "@vortexlabs/vortex-native";
import { useRef } from "react";
import type { TextInstance } from "react-native";
export const DepartureDetails = () => {
const departure = useRef<TextInstance>(null);
return (
<Popover initialFocusRef={departure}>
<Popover.Trigger>
{({ onPress, "aria-expanded": expanded }) => (
<Button onPress={onPress} attributes={{ "aria-expanded": expanded }}>Train details</Button>
)}
</Popover.Trigger>
<Popover.Content ariaLabel="Departure details">
<Text ref={departure} attributes={{ accessible: true }}>Platform 3 at 10:45</Text>
</Popover.Content>
</Popover>
);
};Accessibility
ariaLabel on Popover.Content.