Skip to content

Tooltip

Tooltip Primitive Text Component

Demo


A pop-up presenting relevant information pertaining to an element whenever the element gains keyboard focus or when the mouse hovers over it.

Installation

Terminal window
npx @react-native-reusables/cli@latest add tooltip

Usage

import * as React from 'react';
import { Platform, View } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { Button } from '~/components/ui/button';
import { Tooltip, TooltipContent, TooltipTrigger } from '~/components/ui/tooltip';
import { Text } from '~/components/ui/text';
function Example() {
const insets = useSafeAreaInsets();
const contentInsets = {
top: insets.top,
bottom: insets.bottom,
left: 12,
right: 12,
};
return (
<View className='flex-1 justify-center items-center p-6'>
<Tooltip delayDuration={150}>
<TooltipTrigger asChild>
<Button variant='outline'>
<Text>{Platform.OS === 'web' ? 'Hover me' : 'Press me'}</Text>
</Button>
</TooltipTrigger>
<TooltipContent insets={contentInsets}>
<Text className='native:text-lg'>Add to library</Text>
</TooltipContent>
</Tooltip>
</View>
);
}

Props

Tooltip

Extends View props

PropTypeNote
asChildboolean(optional)
onOpenChange(value: boolean) => void(optional)
delayDurationnumberWeb Only - defaults to 700 (optional)
skipDelayDurationnumberWeb Only - defaults to 300 (optional)
disableHoverableContentboolean(optional)

TooltipTrigger

Extends Pressable props

PropTypeNote
asChildboolean(optional)

TooltipContent

Extends View props

PropTypeNote
asChildboolean(optional)
forceMounttrue | undefined(optional)
alignOffsetnumber(optional)
insetsInsets(optional)
avoidCollisionsboolean(optional)
align’start’ | ‘center’ | ‘end’(optional)
side’top’ | ‘bottom’(optional)
sideOffsetnumber(optional)
disablePositioningStylebooleanNative Only (optional)
collisionBoundaryElement | null | Array<Element | null>Web Only (optional)
sticky’partial’ | ‘always’Web Only (optional)
hideWhenDetachedbooleanWeb Only (optional)
onEscapeKeyDown(ev: Event) => voidWeb Only (optional)
onPointerDownOutside(ev: Event) => voidWeb Only (optional)