Looking for documentation on gluestack-ui with NativeWind (alpha) version? Refer to this link.
This is an illustration of a Themed Popover component with default configuration.
placement
size
function App() {
const [isOpen, setIsOpen] = 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>Popover</ButtonText>
</Button>
)
}}
>
<PopoverBackdrop />
<PopoverContent>
<PopoverHeader>
<Heading size="lg">Welcome!</Heading>
<PopoverCloseButton>
<Icon as={CloseIcon} />
</PopoverCloseButton>
</PopoverHeader>
<PopoverBody>
<Text size="sm">
Join the product tour and start creating your own checklist. Are you
ready to jump in?
</Text>
</PopoverBody>
<PopoverFooter>
<Text size="xs" flex={1}>
Step 2 of 3
</Text>
<ButtonGroup space="md">
<Button variant="outline" action="secondary" onPress={handleClose}>
<ButtonText>Back</ButtonText>
</Button>
<Button onPress={handleClose}>
<ButtonText>Next</ButtonText>
</Button>
</ButtonGroup>
</PopoverFooter>
</PopoverContent>
</Popover>
)
}

Popover with arrow

We have exported PopoverArrow component which can be used to render an arrow for the popover.
placement
size
function App() {
const [isOpen, setIsOpen] = 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>Popover</ButtonText>
</Button>
)
}}
>
<PopoverBackdrop />
<PopoverContent>
<PopoverArrow />
<PopoverHeader>
<Heading size="lg">Welcome!</Heading>
<PopoverCloseButton>
<Icon as={CloseIcon} />
</PopoverCloseButton>
</PopoverHeader>
<PopoverBody>
<Text size="sm">
Join the product tour and start creating your own checklist. Are you
ready to jump in?
</Text>
</PopoverBody>
<PopoverFooter>
<Text size="xs" flex={1}>
Step 2 of 3
</Text>
<ButtonGroup space="md">
<Button variant="outline" action="secondary" onPress={handleClose}>
<ButtonText>Back</ButtonText>
</Button>
<Button onPress={handleClose}>
<ButtonText>Next</ButtonText>
</Button>
</ButtonGroup>
</PopoverFooter>
</PopoverContent>
</Popover>
)
}

API Reference

Import

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 "@gluestack-ui/themed"

Anatomy

The structure provided below can help you identify and understand a Popover component's various parts.
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.
Descendants Styling Props Props to style child components.
Sx Prop
Description
_content
Prop to style PopoverContent Component

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.
Descendants Styling Props Props to style child components.
Sx Prop
Description
_text
Prop to style PopoverCloseButton Text Component
_icon
Prop to style PopoverCloseButton Icon Component

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.

Themed

The themed version of the component is a pre-styled version of the component, which allows you to quickly integrate the component into your project. The component's design and functionality are fully defined, allowing you to focus on the more important aspects of your project. To know more about Themed Library please visit this link.

Props

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

Popover

Name
Value
Default
size
xs | sm | md | lg | full
md
Note: These props are exclusively applicable when utilizing the default configuration of gluestack-ui/config. If you are using a custom theme, these props may not be available.

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 on Avatar

A popover component can enhance the avatar by providing additional information and context in a concise and visually appealing manner.
<Box h="$80">
{/* PhoneIcon, Clock3Icon, MailIcon are imported from 'lucide-react-native' */}
<Popover
trigger={(triggerProps) => {
return (
<HStack>
<Pressable borderRadius="$full" {...triggerProps}>
<Avatar bg="$indigo600">
<AvatarFallbackText>Kevin James</AvatarFallbackText>
</Avatar>
</Pressable>
<VStack ml="$2.5">
<Heading fontSize="$md">Kevin James</Heading>
<Text size="sm">Hi Rachel, What’s up?</Text>
</VStack>
</HStack>
)
}}
>
<PopoverBackdrop />
<PopoverContent w="$80">
<PopoverHeader px="$5" pt="$5">
<HStack>
<Avatar bg="$indigo600">
<AvatarFallbackText>Kevin James</AvatarFallbackText>
</Avatar>
<VStack ml="$2.5">
<Heading fontSize="$md">Kevin James</Heading>
<HStack alignItems="center">
<CircleIcon color="$green700" h="$2" w="$2" />
<Text size="sm" pl="$1.5">
Active
</Text>
</HStack>
</VStack>
</HStack>
</PopoverHeader>
<PopoverBody px="$5" pb="$5">
<VStack space="lg">
<VStack space="sm">
<HStack alignItems="center">
<Icon as={PhoneIcon} size="sm" />
<Text size="sm" ml="$1.5">
(603) 555-0123
</Text>
</HStack>
<HStack alignItems="center">
<Icon as={Clock3Icon} size="sm" />
<Text size="sm" ml="$1.5">
5:21 PM local time
</Text>
</HStack>
<HStack alignItems="center">
<Icon as={MailIcon} size="sm" />
<Text size="sm" ml="$1.5">
kevinjames@sample.com
</Text>
</HStack>
</VStack>
<Button bg="$darkBlue700" $dark-bg="$darkBlue500">
<ButtonText>View Profile</ButtonText>
</Button>
</VStack>
</PopoverBody>
</PopoverContent>
</Popover>
</Box>

Unstyled

All the components in gluestack-ui are unstyled by default. To customize your UI using the extendedTheme, please refer to this link. The import names of components serve as keys to customize each component.

Spec Doc

Explore the comprehensive details of the Popover in this document, including its implementation details, checklist, and potential future additions. Dive into the thought process behind the component and gain insights into its development journey.