Looking for documentation on gluestack-ui v2 with NativeWind? Refer to this link.
This is an illustration of a Themed Tooltip component with default configuration.
placement
<Tooltip
placement="top"
trigger={(triggerProps) => {
return (
<Button h="$24" {...triggerProps}>
<ButtonText>Hover on me!</ButtonText>
</Button>
)
}}
>
<TooltipContent>
<TooltipText>Tooltip</TooltipText>
</TooltipContent>
</Tooltip>

API Reference

Import

To use this component in your project, include the following import statement in your file.
import { Tooltip } from "@gluestack-ui/themed"

Anatomy

The structure provided below can help you identify and understand a Tooltip component's various parts.
export default () => (
<Tooltip>
<TooltipContent>
<TooltipText />
</TooltipContent>
</Tooltip>
)

Component Props

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

Tooltip

It inherits all the properties of React Native's View component.
Prop
Type
Default
Description
isOpen
boolean
false
Whether the tooltip is opened. Useful for controlling the open state.
isDisabled
boolean
false
Whether the tooltip is disabled.
defaultIsOpen
boolean
false
If true, the popover will be opened by default.
onOpen
() => void
true
This function will be invoked when the tooltip is opened.
onClose
() => void
-
This function will be invoked when tooltip is closed. It will also be called when the user attempts to close the tooltip via Escape key or backdrop press.
openDelay
number
0
Duration in ms to wait till displaying the tooltip.
closeDelay
number
0
Duration in ms to wait till hiding the tooltip.
placement
"bottom" | "top" | "right" | "left" | "top left" | "top right" | "bottom left" | "bottom right" | "right top" | "right bottom" | "left top" | "left bottom"
bottom left
Tooltip placement
children
any
-
The content to display inside the tooltip.
closeOnClick
boolean
true
Whether tooltip should be closed on Trigger click.
trigger
() => any
-
Function that returns a React Element. This element will be used as a Trigger for the tooltip.
offset
number
10
Distance between the trigger and the tooltip.
crossOffset
number
-
The additional offset applied along the cross axis between the element and its trigger element.
shouldOverlapWithTrigger
boolean
false
Determines whether tooltip content should overlap with the trigger.
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.
closeOnOverlayClick
boolean
true
Closes tooltip when clicked outside.

TooltipText

Contains all text related layout style props and actions. It inherits all the properties of React Native's Text component.

TooltipContent

Contains all backdrop related layout style props and actions. It inherits all the properties of React Native's View component.
Descendants Styling Props Props to style child components.
Sx Prop
Description
_text
Prop to style TooltipText Component

Accessibility

We have outlined the various features that ensure the Tooltip 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 WAI-ARIA design pattern.

Examples

Tooltip with Heading

A tooltip component with an avatar is a user interface element that displays a small pop-up box of additional information when the user hovers over or interacts with an avatar or an icon.
function App() {
const avatars = [
{
src: "https://example.com.jpg",
alt: "Sandeep Srivastva",
color: "$emerald600",
},
{ src: "https://example.com.jpg", alt: "Arjun Kapoor", color: "$cyan600" },
{
src: "https://example.com.jpg",
alt: "Ritik Sharma ",
color: "$indigo600",
},
]
return (
<Box h="$96" justifyContent="center">
<AvatarGroup flexDirection="row">
<Tooltip
placement={"top"}
trigger={(triggerProps) => {
return (
<Avatar
size="lg"
color="$white"
borderColor="$white"
borderWidth="$2"
$dark-borderColor="$black"
{...triggerProps}
>
<AvatarFallbackText>+ 3</AvatarFallbackText>
</Avatar>
)
}}
>
<TooltipContent
p="$5"
maxWidth="$72"
bg="white"
$dark-bg="$backgroundDark900"
>
<VStack boderRadius="$2" space="md">
<Heading size="sm" lineHeight="$md">
View all members of this channel
</Heading>
<Center>
<Text fontSize="$sm" lineHeight="$md">
Includes John, Sarah, Mike, Emily
</Text>
<Text fontSize="$sm" lineHeight="$md">
and David
</Text>
</Center>
</VStack>
</TooltipContent>
</Tooltip>
{avatars.map((avatar, index) => {
return (
<Avatar
key={index}
size="lg"
borderColor="$white"
borderWidth="$2"
bgColor={avatar.color}
$dark-bordeColor="$black"
>
<AvatarFallbackText>{avatar.alt}</AvatarFallbackText>
</Avatar>
)
})}
</AvatarGroup>
</Box>
)
}

Tooltip with Icon

A tooltip component with an icon is a user interface element that provides contextual information or explanatory text when the user hovers over or interacts with an icon.
function App() {
return (
<Box h="$96" justifyContent="center">
<Tooltip
placement={"top"}
trigger={(triggerProps) => {
return (
<Avatar size="md" {...triggerProps} bg="$indigo600">
<Icon as={Edit} color="$white" size="sm" />
</Avatar>
)
}}
>
<TooltipContent bg="$white" $dark-bg="$backgroundDark900">
<Box p="$2.5" boderRadius="$2">
<Text size="sm">New message</Text>
<HStack space="xs" p="$1" ml="$3">
<Avatar size="xs" bg="$trueGray500" rounded="$sm">
<Icon as={Command} color="$white" />
</Avatar>
<Avatar size="xs" bg="$trueGray500" rounded="$sm">
<AvatarFallbackText>N</AvatarFallbackText>
</Avatar>
</HStack>
</Box>
</TooltipContent>
</Tooltip>
</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 Tooltip 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.