Skip to Content
ComponentsTooltip

Tooltip

Popup with brief information shown when user interacts with an element using keyboard focus or mouse hover.

Documentation

Usage

import { Button, Tooltip } from "@optiaxiom/react"; export function App() { return ( <Tooltip content="Sample tooltip content"> <Button>Hover me</Button> </Tooltip> ); }

Controlled

Use the open and defaultOpen props to toggle between controlled and uncontrolled usage. And combine it with onOpenChange to listen for changes to the state.

Open: false

"use client"; import { Button, Flex, Text, Tooltip } from "@optiaxiom/react"; import { useState } from "react"; export function App() { const [open, setOpen] = useState(false); return ( <Flex gap="12"> <Tooltip content="This is a controlled tooltip" onOpenChange={setOpen} open={open} > <Button>Hover me</Button> </Tooltip> <Text>Open: {open ? "true" : "false"}</Text> </Flex> ); }

Placement

Use the side and align props to control where the tooltip is placed by default.

import { Button, Grid, Tooltip } from "@optiaxiom/react"; import { Fragment } from "react"; export function App() { return ( <Grid gap="8" gridTemplateColumns="3"> {(["top", "right", "bottom", "left"] as const).map((side) => ( <Fragment key={side}> {(["start", "center", "end"] as const).map((align) => ( <Tooltip align={align} content={`${side} ${align}`} key={align} side={side} > <Button justifyContent="center" py="20"> {side} {align} </Button> </Tooltip> ))} </Fragment> ))} </Grid> ); }

Auto

Use the auto prop to only show the tooltip when the underlying text is clipped.

"use client"; import type { ComponentPropsWithoutRef } from "react"; import { Flex, Link, Text, Tooltip } from "@optiaxiom/react"; export function App({ auto = true, }: Pick<ComponentPropsWithoutRef<typeof Tooltip>, "auto">) { return ( <Flex alignItems="start" fontSize="md" w="224"> <Tooltip auto={auto} content="The quick brown fox jumps over the lazy dog." > <Link href="data:,"> <Text lineClamp="1"> The quick brown fox jumps over the lazy dog. </Text> </Link> </Tooltip> <Tooltip auto={auto} content="Sample non-clipped link"> <Link href="data:,">Sample non-clipped link</Link> </Tooltip> </Flex> ); }

Delay

Use the delayDuration prop to control how long to wait to open the tooltip after mouse hover.

import { Button, Flex, Tooltip } from "@optiaxiom/react"; export function App() { return ( <Flex flexDirection="row"> <Tooltip content="Sample tooltip content" delayDuration={0}> <Button>Delay duration 0ms</Button> </Tooltip> <Tooltip content="Sample tooltip content"> <Button>Delay duration 700ms</Button> </Tooltip> </Flex> ); }

Props

Tooltip

Doesn't render its own HTML element and forwards all props to the content component instead.

Prop

align

"center" | "end" | "start"

aria-label

A more descriptive label for accessibility purpose

string

auto

Enable this option to only show the tooltip when children is partially hidden due to text overflow.

false | true

className

string

content

The tooltip content.

ReactNode

defaultOpen

The initial open state in uncontrolled mode.

false | true

delayDuration

The duration from when the pointer enters the trigger until the tooltip gets opened. This will override the prop with the same name passed to Provider. @defaultValue 700

number

disabled

Whether to show or hide tooltip even if there’s content.

false | true

onEscapeKeyDown

Event handler called when the escape key is down. Can be prevented.

(event: KeyboardEvent) => void

onOpenChange

Handler that is called when the open state changes.

(open: boolean) => void

onPointerDownOutside

Event handler called when the a pointerdown event happens outside of the Tooltip. Can be prevented.

(event: PointerDownOutsideEvent) => void

open

The open state in controlled mode.

false | true

side

"bottom" | "left" | "right" | "top"

TooltipProvider

Doesn't render its own HTML element.

Prop

delayDuration

The duration from when the pointer enters the trigger until the tooltip gets opened. @defaultValue 700

number

disableHoverableContent

When true, trying to hover the content will result in the tooltip closing as the pointer leaves the trigger.

false | true

Default: true

skipDelayDuration

How much time a user has to enter another trigger without incurring a delay again. @defaultValue 300

number

Changelog

0.1.0

  • Added component
Last updated on