Popover

Contextual pop-ups offer info or actions conveniently, enhancing user flow without page changes.
Installation
API Reference
This is an illustration of Popover component.
placement
size
function App() {
const [isOpen, setIsOpen] = React.useState(false)
const handleOpen = () => {
setIsOpen(true)
}
const handleClose = () => {
setIsOpen(false)
}
return (
<Popover
isOpen={isOpen}
onClose={handleClose}
onOpen={handleOpen}
placement="bottom"
size="md"
trigger={(triggerProps) => {
return (
<Button {...triggerProps}>
<ButtonText>Open Popover</ButtonText>
</Button>
)
}}
>
<PopoverBackdrop />
<PopoverContent>
<PopoverArrow />
<PopoverBody>
<Text size={props.size} className="text-typography-900">
Alex, Annie and many others are already enjoying the Pro features,
don't miss out on the fun!
</Text>
</PopoverBody>
</PopoverContent>
</Popover>
)
}

Installation

Run the following command:

npx gluestack-ui add popover

API Reference

To use this component in your project, include the following import statement in your file.
import {
Popover,
PopoverBackdrop,
PopoverContent,
PopoverArrow,
PopoverHeader,
PopoverCloseButton,
PopoverBody,
PopoverFooter,
} from "@/components/ui/popover"
export default () => (
<Popover>
<PopoverBackdrop />
<PopoverContent>
<PopoverArrow />
<PopoverHeader>
<PopoverCloseButton />
</PopoverHeader>
<PopoverBody />
<PopoverFooter />
</PopoverContent>
</Popover>
)

Component Props

This section provides a comprehensive reference list for the component props, detailing descriptions, properties, types, and default behavior for easy project integration.

Popover

It inherits all the properties of React Native's View component.
Prop
Type
Default
Description
defaultIsOpen
boolean
-
Specifies the default open state of the popover.
isOpen
boolean
-
If true, the popover will open. Useful for controllable state behavior.
trapFocus
boolean
true
Whether popover should trap focus.
focusScope
boolean
true
Whether focus should be outside of popover or not
shouldFlip
boolean
true
Whether the element should flip its orientation (e.g. top to bottom or left to right) when there is insufficient room for it to render completely.
initialFocusRef
React.RefObject<any>
-
The ref of element to receive focus when the popover opens.
finalFocusRef
React.RefObject<any>
-
The ref of element to receive focus when the popover closes
trigger
() => any
-
Function that returns a React Element. This element will be used as a Trigger for the popover.
crossOffset
number
-
The additional offset applied along the cross axis between the element and its trigger element.
offset
number
-
The additional offset applied along the main axis between the element and its trigger element.
shouldOverlapWithTrigger
boolean
false
Determines whether popover content should overlap with the trigger.
isKeyboardDismissable
boolean
-
If true, the keyboard can dismiss the popover.
placement
'top' | 'top left' | 'top right' | 'bottom' | 'bottom left' | 'bottom right' | 'right' | 'right top' | 'right bottom' | 'left' | 'left top' | 'left bottom'
'bottom'
Popover placement
useRNModal
boolean
false
If true, renders react-native native modal.
avoidKeyboard
boolean
-
If true, the popover will avoid the keyboard.
onOpen
() => any
-
This function will be invoked when popover is opened.
onClose
() => any
-
This function will be invoked when popover is closed. It'll also be called when user attempts to close the popover via Escape key or backdrop press.
children
any
-
The content to display inside the popover.

PopoverBackdrop

It is React Native's Pressable component, created using @legendapp/motion's createMotionAnimatedComponent function to add animation to the component. You can use any declarative animation library you prefer.

PopoverContent

Contains all backdrop related layout style props and actions. It is @legendapp/motion's Motion.View component. You can use any declarative animation library you prefer.

PopoverHeader

It inherits all the properties of React Native's View component.

PopoverFooter

It inherits all the properties of React Native's View component.

PopoverBody

It inherits all the properties of React Native's View component.

PopoverCloseButton

It inherits all the properties of React Native's Pressable component.

Features

  • Keyboard support for actions.

Accessibility

We have outlined the various features that ensure the Popover component is accessible to all users, including those with disabilities. These features help ensure that your application is inclusive and meets accessibility standards. It adheres to the Dialog WAI-ARIA design pattern..

Keyboard

  • Space: Opens/closes the popover.
  • Enter: Opens/closes the popover.
  • Tab: Moves focus to the next focusable element.
  • Shift + Tab: Moves focus to the previous focusable element.
  • Esc: Closes the popover and moves focus to PopoverTrigger.

Screen Reader

  • VoiceOver: When we click on button, the screen reader will announce Popover, menu expanded, button and when we close it then it says Popover, menu collapsed, button.

Props

Popover component is created using ScrollView component from react-native. It extends all the props supported by React Native ScrollView and the props mentioned below.

Popover

Name
Value
Default
size
xs | sm | md | lg | full
md

Examples

The Examples section provides visual representations of the different variants of the component, allowing you to quickly and easily determine which one best fits your needs. Simply copy the code and integrate it into your project.

Popover used along with multiple Avatars

function App() {
const [isOpen, setIsOpen] = React.useState(false)
const handleOpen = () => {
setIsOpen(true)
}
const handleClose = () => {
setIsOpen(false)
}
return (
<Popover
isOpen={isOpen}
onClose={handleClose}
onOpen={handleOpen}
{...props}
trigger={(triggerProps) => {
return (
<Button {...triggerProps} size="sm">
<ButtonText>Open Popover</ButtonText>
</Button>
)
}}
>
<PopoverBackdrop />
<PopoverContent className="w-full max-w-[420px] p-4">
<PopoverArrow />
<PopoverBody
className=""
contentContainerClassName="flex flex-row gap-4"
>
<AvatarGroup className="flex-row items-center">
<Avatar className="w-9 h-9 border-[1.5px] border-outline-0">
<AvatarFallbackText>John Doe</AvatarFallbackText>
<AvatarImage
source={{
uri: "https://i.ibb.co/PF4vFQk/a130347c432c7b83615044cec215d824.jpg",
}}
alt="imageAltText"
/>
</Avatar>
<Avatar className="w-9 h-9 border-[1.5px] border-outline-0">
<AvatarFallbackText>John Doe</AvatarFallbackText>
<AvatarImage
source={{
uri: "https://i.ibb.co/MgrMrRc/Avatar-2.png",
}}
alt="imageAltText"
/>
</Avatar>
<Avatar className="w-9 h-9 border-[1.5px] border-outline-0">
<AvatarFallbackText>John Doe</AvatarFallbackText>
<AvatarImage
source={{
uri: "https://i.ibb.co/BLRZt0p/Avatar-6.jpg",
}}
alt="imageAltText"
/>
</Avatar>
<Avatar className="w-9 h-9 border-[1.5px] border-outline-0 group-[.avatar-group]/avatar-group:ml-0">
<AvatarFallbackText>John Doe</AvatarFallbackText>
<AvatarImage
source={{
uri: "https://i.ibb.co/4VVsQ0K/Avatar-7.png",
}}
alt="imageAltText"
/>
</Avatar>
</AvatarGroup>
<Text className="text-typography-900" size="sm">
Alex, Annie and many others are already enjoying the Pro features,
don't miss out on the fun!
</Text>
</PopoverBody>
</PopoverContent>
</Popover>
)
}

Popover with CTA

function App() {
const [isOpen, setIsOpen] = React.useState(false)
const [values, setValues] = React.useState(["work"])
const handleOpen = () => {
setIsOpen(true)
}
const handleClose = () => {
setIsOpen(false)
}
return (
<Popover
isOpen={isOpen}
onClose={handleClose}
onOpen={handleOpen}
offset={8}
{...props}
trigger={(triggerProps) => {
return (
<Button {...triggerProps} className="gap-2">
<ButtonText>Purchase Plan</ButtonText>
<ButtonIcon as={ChevronRightIcon} />
</Button>
)
}}
>
<PopoverBackdrop />
<PopoverContent className="w-full max-w-[420px] p-5 gap-6 pl-4 shadow-hard-5">
<PopoverBody>
<Heading className="pl-1">
Are you interested in using Pro for work or personal use?
</Heading>
<Text className="pt-2 pb-6 pl-1" size="sm">
We can recommend plans that are right for you. With our personalized
approach, you can trust that the plans we recommend will align
perfectly with your goals.
</Text>
<CheckboxGroup
value={values}
onChange={(keys) => {
setValues(keys)
}}
className="pl-1"
>
<VStack space="sm">
<Checkbox value="projects">
<CheckboxIndicator>
<CheckboxIcon as={CheckIcon} />
</CheckboxIndicator>
<CheckboxLabel>For personal projects</CheckboxLabel>
</Checkbox>
<Checkbox value="work">
<CheckboxIndicator>
<CheckboxIcon as={CheckIcon} />
</CheckboxIndicator>
<CheckboxLabel>For work</CheckboxLabel>
</Checkbox>
</VStack>
</CheckboxGroup>
</PopoverBody>
<PopoverFooter>
<Pressable
className="px-4 bg-primary-500 rounded w-full"
onPress={handleClose}
>
<Button onPress={handleClose} size="sm" className="gap-2">
<ButtonText>Next</ButtonText>
<ButtonIcon as={ArrowRightIcon} />
</Button>
</Pressable>
</PopoverFooter>
</PopoverContent>
</Popover>
)
}

Popover with Image

function App() {
const [isOpen, setIsOpen] = React.useState(false)
const handleOpen = () => {
setIsOpen(true)
}
const handleClose = () => {
setIsOpen(false)
}
return (
<Popover
isOpen={isOpen}
onClose={handleClose}
onOpen={handleOpen}
offset={8}
{...props}
trigger={(triggerProps) => {
return (
<Button {...triggerProps} size="sm">
<ButtonText>Claim Offer</ButtonText>
</Button>
)
}}
>
<PopoverBackdrop />
<PopoverContent className="shadow-soft-1 h-full max-w-full p-0">
<PopoverBody
className=""
contentContainerClassName="flex flex-col sm:flex-row w-full h-full"
>
<Image
source={{
uri: "https://i.ibb.co/TqD9vBY/popover-image-1-11zon.jpg",
}}
alt="image"
className="sm:h-[270px] sm:w-[211px] h-[150px] w-full"
/>
<VStack className="items-center justify-center w-full max-w-[344px] sm:mx-8 p-4 sm:p-0">
<Text size="sm" className="text-typography-950">
Sign up to the newsletter and get
</Text>
<Heading size="3xl" className="text-typography-950 my-1">
25% Off
</Heading>
<Input variant="outline" size="sm" className="my-4 w-full">
<InputField placeholder="youremail@address.com" />
</Input>
<Button size="xs" isDisabled className="w-full">
<ButtonText>Subscribe</ButtonText>
</Button>
</VStack>
</PopoverBody>
</PopoverContent>
</Popover>
)
}

Popover with InputField

function App() {
const [isOpen, setIsOpen] = React.useState(false)
const handleOpen = () => {
setIsOpen(true)
}
const handleClose = () => {
setIsOpen(false)
}
return (
<Popover
isOpen={isOpen}
onClose={handleClose}
onOpen={handleOpen}
offset={8}
{...props}
trigger={(triggerProps) => {
return (
<Button {...triggerProps} className="gap-2">
<ButtonText>Share</ButtonText>
<ButtonIcon as={ShareIcon} />
</Button>
)
}}
>
<PopoverBackdrop />
<PopoverContent className="p-5 gap-8 shadow-hard-5 max-w-[473px] w-full">
<PopoverHeader className="w-full gap-3">
<Input size="sm" className="flex-1">
<InputField placeholder="Email separated by commas" />
</Input>
<Button size="sm" className="text-blue-600">
<ButtonText className="text-blue-50">Invite</ButtonText>
</Button>
</PopoverHeader>
<PopoverBody className="" contentContainerClassName="gap-6">
<Heading size="sm">People with access</Heading>
<VStack space="lg">
<VStack space="lg">
<HStack space="4xl" className="items-center">
<HStack space="md" className="w-full items-center">
<Avatar>
<AvatarFallbackText>JC</AvatarFallbackText>
<AvatarImage
source={{
uri: "https://i.ibb.co/7R4DyhQ/Avatar-1.jpg",
}}
alt="imageAltText"
/>
</Avatar>
<VStack>
<Text
size="sm"
className="font-semibold text-typography-900"
>
Jane Cooper
</Text>
<Text size="xs">janecooper09@gmail.com</Text>
</VStack>
</HStack>
<Button variant="link" size="xs" className="gap-1 sm:px-3.5">
<ButtonText>Can edit</ButtonText>
<ButtonIcon as={ChevronDownIcon} />
</Button>
</HStack>
<HStack space="4xl" className="items-center">
<HStack space="md" className="w-full items-center">
<Avatar>
<AvatarFallbackText>JC</AvatarFallbackText>
<AvatarImage
source={{
uri: "https://i.ibb.co/sQwcjSZ/Avatar-2.png",
}}
alt="imageAltText"
/>
</Avatar>
<VStack>
<Text
size="sm"
className="font-semibold text-typography-900"
>
Catherine Miller
</Text>
<Text size="xs">ctherienemiller88@gmail.com</Text>
</VStack>
</HStack>
<Button variant="link" size="xs" className="gap-1 sm:px-3.5">
<ButtonText>Admin</ButtonText>
<ButtonIcon as={ChevronDownIcon} />
</Button>
</HStack>
<HStack space="4xl" className="items-center">
<HStack space="md" className="w-full items-center">
<Avatar>
<AvatarFallbackText>JC</AvatarFallbackText>
<AvatarImage
source={{
uri: "https://i.ibb.co/XXkHzcZ/Avatar-3.png",
}}
/>
</Avatar>
<VStack>
<Text
size="sm"
className="font-semibold text-typography-900"
>
John Brown
</Text>
<Text size="xs">johnb345@gmail.com</Text>
</VStack>
</HStack>
<Button variant="link" size="xs" className="gap-1 sm:px-3.5">
<ButtonText>Can edit</ButtonText>
<ButtonIcon as={ChevronDownIcon} />
</Button>
</HStack>
</VStack>
</VStack>
</PopoverBody>
</PopoverContent>
</Popover>
)
}