Tooltip

January 21, 2026 ยท View on GitHub

A customizable tooltip component built on top of react-tooltip.

Usage

import { Tooltip, TooltipContainer, withTooltip } from "@docspace/ui-kit/components/tooltip";

Basic Usage

<div
  data-tooltip-id="my-tooltip"
  data-tooltip-content="Hello, I'm a tooltip!"
>
  Hover me
</div>
<Tooltip id="my-tooltip" />

With TooltipContainer

TooltipContainer is a polymorphic component that automatically handles tooltip events.

<TooltipContainer title="Tooltip text" as="button">
  Hover me
</TooltipContainer>

With Dynamic Content

<div data-tooltip-id="dynamic-tooltip">Hover for dynamic content</div>
<Tooltip
  id="dynamic-tooltip"
  getContent={({ content, activeAnchor }) => (
    <div>
      <Text isBold>Dynamic Content</Text>
      <Text>{content}</Text>
    </div>
  )}
/>

Click to Open

<div
  data-tooltip-id="click-tooltip"
  data-tooltip-content="Click-triggered tooltip"
>
  Click me
</div>
<Tooltip id="click-tooltip" openOnClick />

Using withTooltip HOC

The withTooltip higher-order component wraps any component to add tooltip functionality.

import { withTooltip } from "@docspace/ui-kit/components/tooltip";

const MyButton = React.forwardRef((props, ref) => (
  <button ref={ref} {...props}>
    {props.children}
  </button>
));

const ButtonWithTooltip = withTooltip(MyButton);

// Usage
<ButtonWithTooltip title="Button tooltip">Click me</ButtonWithTooltip>

RootTooltip

For global tooltip support, add RootTooltip to your app root.

import { RootTooltip } from "@docspace/ui-kit/components/tooltip";

function App() {
  return (
    <>
      <RootTooltip />
      {/* Your app content */}
    </>
  );
}

Tooltip Properties

PropTypeRequiredValuesDefaultDescription
idstring---Unique identifier for the tooltip
placeTTooltipPlace-top, top-start, top-end, right, right-start, right-end, bottom, bottom-start, bottom-end, left, left-start, left-endtopTooltip placement
getContentfunction---Function to generate tooltip content dynamically
afterHidefunction---Callback after tooltip is hidden
afterShowfunction---Callback after tooltip is shown
offsetnumber--4Distance from anchor element
childrenReactNode---Static tooltip content
isOpenboolean---Control tooltip visibility programmatically
clickableboolean--falseAllow interaction with tooltip content
openOnClickboolean--falseOpen on click instead of hover
floatboolean--falseFollow mouse position
anchorSelectstring---CSS selector to attach tooltip to multiple elements
noArrowboolean--trueHide tooltip arrow
opacitynumber--1Tooltip opacity
imperativeModeOnlyboolean--falseDisable default tooltip behavior, use ref methods only
delayShownumber---Delay before showing tooltip (ms)
classNamestring---Additional CSS class
styleCSSProperties---Container styles
tooltipStyleCSSProperties---Tooltip element styles
colorstring---Background color of the tooltip
maxWidthstring---Maximum width of the tooltip
fallbackAxisSideDirectionstring-none, start, endnoneFallback direction when preferred placement unavailable
noUserSelectboolean--falseDisable text selection in tooltip
zIndexnumber---CSS z-index value
dataTestIdstring---Data attribute for testing

Anchor Element Data Attributes

AttributeTypeRequiredDescription
data-tooltip-idstring-Links element to tooltip by id
data-tooltip-contentstring-Tooltip text content
data-tooltip-placestring-Override tooltip placement
data-tooltip-offsetnumber-Override tooltip offset

TooltipContainer Properties

PropTypeRequiredDefaultDescription
asstring-divHTML element to render
titlestring--Tooltip content
childrenReactNode--Container content

Supports all HTML attributes for the rendered element.

withTooltip HOC Props

Components wrapped with withTooltip receive these additional props:

PropTypeDescription
titlestringTooltip content
tooltipContentReactNodeAlternative to title
tooltipPlaceTTooltipPlaceTooltip placement
tooltipFitToContentbooleanFit tooltip width to content

Types

import type {
  TooltipProps,
  TTooltipPlace,
  TFallbackAxisSideDirection,
  TGetTooltipContent,
  WithTooltipProps,
} from "@docspace/ui-kit/components/tooltip";