Skip to main content
196

Search Lumen

Find components, APIs, guides, and recipes.

GitHub
Web docs
Overlays and menus

useTooltip

Manages tooltip show/hide with configurable delay, hover and focus triggers, and Escape key dismissal.

Live component preview · Astro

Explore Tooltip

Try the component this hook connects to. The preview uses the Astro adapter; the React example below uses useTooltip.

Save changes

React usage

Import from @santi020k/lumen-react and spread the controller props onto the matching components.

tsxuseTooltip example
import { Button, Tooltip, TooltipContent } from '@santi020k/lumen-react'
import { useTooltip } from '@santi020k/lumen-react'

export function SaveButton() {
  const tooltip = useTooltip({ delay: 300 })

  return (
    <Tooltip {...tooltip.rootProps}>
      <Button>Save</Button>
      <TooltipContent {...tooltip.tooltipProps}>Save your changes</TooltipContent>
    </Tooltip>
  )
}
import { Button, Tooltip, TooltipContent } from '@santi020k/lumen-react'
import { useTooltip } from '@santi020k/lumen-react'

export function SaveButton() {
  const tooltip = useTooltip({ delay: 300 })

  return (
    <Tooltip {...tooltip.rootProps}>
      <Button>Save</Button>
      <TooltipContent {...tooltip.tooltipProps}>Save your changes</TooltipContent>
    </Tooltip>
  )
}

Load @santi020k/lumen-react/styles.css once in your application. With React Server Components, put 'use client' at the top of the module that calls the hook. Follow the React setup guide for the framework boundary.

Options

PropertyTypeDefaultDescription
delaynumber400Milliseconds to wait before showing the tooltip on hover.
defaultOpenbooleanfalseInitial open state.
openboolean-Controlled open state.
onOpenChange(open: boolean) => void-Callback fired when the tooltip opens or closes.

Controller return values

PropertyTypeDescription
rootPropsLumenProps<"span">Spread onto the wrapper span. Includes hover and focus listeners.
tooltipPropsLumenProps<"span">Spread onto the tooltip content span. Includes role="tooltip" and visibility.
openbooleanCurrent open state.
close() => voidClose the tooltip.
setOpenDispatch<SetStateAction<boolean>>State setter for controlled usage.
Web docsFull catalog