Components

Tooltip

A popup that appears when an element is hovered or focused, showing a hint for sighted users

import { Tooltip } from "@nyte-ai/ui/tooltip";

A hint that appears on hover or focus. Reach for it to label an icon-only control in a dense interface.

No Nyte styling here.

Usage

  • Give the trigger an aria-label that closely matches the tooltip text. The tooltip does not label the trigger.
  • Tooltips are disabled on touch devices. Never put information there that a user would miss.
  • If the trigger exists to open the popup, use Popover with openOnHover instead. If the trigger does something else, it is a tooltip.
  • For feedback after an action, use Toast.
  • The tooltip opens after delay, which is 600ms, and closes after closeDelay, which is 0. Both live on the trigger.
  • Wrap a group in Tooltip.Provider to share one delay. Once one tooltip is visible, the next opens instantly, for timeout milliseconds after the last one closed.
  • Tooltip.Positioner places the popup. It defaults to side="top" and align="center". Pass sideOffset for the gap.
  • Tooltip.Arrow only works inside the positioner.
  • Set trackCursorAxis on the root to follow the pointer along x, y, or both.

Anatomy

<Tooltip.Provider>
  <Tooltip.Root>
    <Tooltip.Trigger />
    <Tooltip.Portal>
      <Tooltip.Positioner>
        <Tooltip.Popup>
          <Tooltip.Arrow />
          <Tooltip.Viewport />
        </Tooltip.Popup>
      </Tooltip.Positioner>
    </Tooltip.Portal>
  </Tooltip.Root>
</Tooltip.Provider>

Examples

An icon button with a matching label.

<Tooltip.Root>
  <Tooltip.Trigger render={<Button size="icon-sm" variant="ghost" />} aria-label="Copy output">
    <IconClipboard size={14} />
  </Tooltip.Trigger>
  <Tooltip.Portal>
    <Tooltip.Positioner sideOffset={6}>
      <Tooltip.Popup>Copy output</Tooltip.Popup>
    </Tooltip.Positioner>
  </Tooltip.Portal>
</Tooltip.Root>

A toolbar of triggers sharing one delay, so moving along the row does not re-wait.

<Tooltip.Provider delay={400} closeDelay={100}>
  <Tooltip.Root>…</Tooltip.Root>
  <Tooltip.Root>…</Tooltip.Root>
</Tooltip.Provider>

Animate the popup's position with CSS transitions on left, right, top, and bottom of the positioner, and its size with width and height on the popup.

Props

The part tables below come from Base UI, MIT, © Material-UI SAS.

Provider

Provides a shared delay for multiple tooltips. The grouping logic ensures that once a tooltip becomes visible, the adjacent tooltips will be shown instantly.

Provider Props:

PropTypeDefaultDescription
delaynumber-How long to wait before opening the tooltip on hover. Specified in milliseconds.
closeDelaynumber-How long to wait before closing a tooltip. Specified in milliseconds.
timeoutnumber400Another tooltip will open instantly if the previous tooltip is closed within this timeout. Specified in milliseconds.
childrenReact.ReactNode--

Root

Groups all parts of the tooltip. Doesn't render its own HTML element.

Root Props:

PropTypeDefaultDescription
defaultOpenbooleanfalseWhether the tooltip is initially open. To render a controlled tooltip, use the open prop instead.
openboolean-Whether the tooltip is currently open.
onOpenChange((open: boolean, eventDetails: Tooltip.Root.ChangeEventDetails) => void)-Event handler called when the tooltip is opened or closed.
actionsRefReact.RefObject<Tooltip.Root.Actions | null>-A ref to imperative actions. unmount: Unmounts the tooltip popup.close: Closes the tooltip imperatively when called.
defaultTriggerIdstring | null-ID of the trigger that the tooltip is associated with. This is useful in conjunction with the defaultOpen prop to create an initially open tooltip.
handleTooltip.Handle<Payload>-A handle to associate the tooltip with a trigger. If specified, allows external triggers to control the tooltip's open state. Can be created with the Tooltip.createHandle() method.
onOpenChangeComplete((open: boolean) => void)-Event handler called after any animations complete when the tooltip is opened or closed.
triggerIdstring | null-ID of the trigger that the tooltip is associated with. This is useful in conjunction with the open prop to create a controlled tooltip. There's no need to specify this prop when the tooltip is uncontrolled (that is, when the open prop is not set).
trackCursorAxis'none' | 'x' | 'y' | 'both''none'Determines which axis the tooltip should track the cursor on.
disabledbooleanfalseWhether the tooltip is disabled.
disableHoverablePopupbooleanfalseWhether the tooltip contents can be hovered without closing the tooltip.
childrenReact.ReactNode | PayloadChildRenderFunction<Payload>-The content of the tooltip. This can be a regular React node or a render function that receives the payload of the active trigger.

Trigger

An element to attach the tooltip to. Renders a <button> element.

Trigger Props:

PropTypeDefaultDescription
closeOnClickbooleantrueWhether the tooltip should close when this trigger is clicked.
handleTooltip.Handle<Payload>-A handle to associate the trigger with a tooltip.
payloadPayload-A payload to pass to the tooltip when it is opened.
disabledbooleanfalseIf true, the tooltip will not open when interacting with this trigger. Note that this doesn't apply the disabled attribute to the trigger element. If you want to disable the trigger element itself, you can pass the disabled prop to the trigger element via the render prop.
delaynumber600How long to wait before opening the tooltip on hover. Specified in milliseconds.
closeDelaynumber0How long to wait before closing the tooltip. Specified in milliseconds.
classNamestring | ((state: Tooltip.Trigger.State) => string | undefined)-CSS class applied to the element, or a function that returns a class based on the component's state.
styleReact.CSSProperties | ((state: Tooltip.Trigger.State) => React.CSSProperties | undefined)-Style applied to the element, or a function that returns a style object based on the component's state.
renderReactElement | ((props: HTMLProps, state: Tooltip.Trigger.State) => ReactElement)-Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

Trigger Data Attributes:

AttributeTypeDescription
data-popup-open-Present when the corresponding tooltip is open.
data-trigger-disabled-Present when the trigger is disabled, either by the disabled prop or by a parent <Tooltip.Root> component.

Portal

A portal element that moves the popup to a different part of the DOM. By default, the portal element is appended to <body>. Renders a <div> element.

Portal Props:

PropTypeDefaultDescription
containerHTMLElement | ShadowRoot | React.RefObject<HTMLElement | ShadowRoot | null> | null-A parent element to render the portal element into.
classNamestring | ((state: Tooltip.Portal.State) => string | undefined)-CSS class applied to the element, or a function that returns a class based on the component's state.
styleReact.CSSProperties | ((state: Tooltip.Portal.State) => React.CSSProperties | undefined)-Style applied to the element, or a function that returns a style object based on the component's state.
keepMountedbooleanfalseWhether to keep the portal mounted in the DOM while the popup is hidden.
renderReactElement | ((props: HTMLProps, state: Tooltip.Portal.State) => ReactElement)-Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

Positioner

Positions the tooltip against the trigger. Renders a <div> element.

Positioner Props:

PropTypeDefaultDescription
disableAnchorTrackingbooleanfalseWhether to disable the popup from tracking any layout shift of its positioning anchor.
alignAlign'center'How to align the popup relative to the specified side.
alignOffsetnumber | OffsetFunction0Additional offset along the alignment axis in pixels. Also accepts a function that returns the offset to read the dimensions of the anchor and positioner elements, along with its side and alignment. The function takes a data object parameter with the following properties: data.anchor: the dimensions of the anchor element with properties width and height.data.positioner: the dimensions of the positioner element with properties width and height.data.side: which side of the anchor element the positioner is aligned against.data.align: how the positioner is aligned relative to the specified side.
sideSide'top'Which side of the anchor element to align the popup against. May automatically change to avoid collisions.
sideOffsetnumber | OffsetFunction0Distance between the anchor and the popup in pixels. Also accepts a function that returns the distance to read the dimensions of the anchor and positioner elements, along with its side and alignment. The function takes a data object parameter with the following properties: data.anchor: the dimensions of the anchor element with properties width and height.data.positioner: the dimensions of the positioner element with properties width and height.data.side: which side of the anchor element the positioner is aligned against.data.align: how the positioner is aligned relative to the specified side.
arrowPaddingnumber5Minimum distance to maintain between the arrow and the edges of the popup. Use it to prevent the arrow element from hanging out of the rounded corners of a popup.
anchorElement | VirtualElement | React.RefObject<Element | null> | (() => Element | VirtualElement | null) | null-An element to position the popup against. By default, the popup will be positioned against the trigger.
collisionAvoidanceCollisionAvoidance-Determines how to handle collisions when positioning the popup. side controls overflow on the preferred placement axis (top/bottom or left/right): 'flip': keep the requested side when it fits; otherwise try the opposite side (top and bottom, or left and right).'shift': never change side; keep the requested side and move the popup within the clipping boundary so it stays visible.'none': do not correct side-axis overflow. align controls overflow on the alignment axis (start/center/end): 'flip': keep side, but swap start and end when the requested alignment overflows.'shift': keep side and requested alignment, then nudge the popup along the alignment axis to fit.'none': do not correct alignment-axis overflow. fallbackAxisSide controls fallback behavior on the perpendicular axis when the preferred axis cannot fit: 'start': allow perpendicular fallback and try the logical start side first (top before bottom, or left before right in LTR).'end': allow perpendicular fallback and try the logical end side first (bottom before top, or right before left in LTR).'none': do not fallback to the perpendicular axis. When side is 'shift', explicitly setting align only supports 'shift' or 'none'. If align is omitted, it defaults to 'flip'.
collisionBoundaryBoundary'clipping-ancestors'An element or a rectangle that delimits the area that the popup is confined to.
collisionPaddingPadding5Additional space to maintain from the edge of the collision boundary.
stickybooleanfalseWhether to maintain the popup in the viewport after the anchor element was scrolled out of view.
positionMethod'absolute' | 'fixed''absolute'Determines which CSS position property to use.
classNamestring | ((state: Tooltip.Positioner.State) => string | undefined)-CSS class applied to the element, or a function that returns a class based on the component's state.
styleReact.CSSProperties | ((state: Tooltip.Positioner.State) => React.CSSProperties | undefined)-Style applied to the element, or a function that returns a style object based on the component's state.
renderReactElement | ((props: HTMLProps, state: Tooltip.Positioner.State) => ReactElement)-Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

alignOffset Prop Example:

<Positioner
  alignOffset={({ side, align, anchor, positioner }) => {
    return side === 'top' || side === 'bottom' ? anchor.width : anchor.height;
  }}
/>

sideOffset Prop Example:

<Positioner
  sideOffset={({ side, align, anchor, positioner }) => {
    return side === 'top' || side === 'bottom' ? anchor.height : anchor.width;
  }}
/>

collisionAvoidance Prop Example:

<Positioner
  collisionAvoidance={{
    side: 'shift',
    align: 'shift',
    fallbackAxisSide: 'none',
  }}
/>

Positioner Data Attributes:

AttributeTypeDescription
data-open-Present when the tooltip is open.
data-closed-Present when the tooltip is closed.
data-anchor-hidden-Present when the anchor is hidden.
data-align'start' | 'center' | 'end'Indicates how the popup is aligned relative to specified side.
data-side'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start'Indicates which side the popup is positioned relative to the trigger.

Positioner CSS Variables:

VariableTypeDescription
--anchor-heightnumberThe anchor's height.
--anchor-widthnumberThe anchor's width.
--available-heightnumberThe available height between the trigger and the edge of the viewport.
--available-widthnumberThe available width between the trigger and the edge of the viewport.
--positioner-heightnumberThe height of the tooltip's positioner. It is important to set height to this value when using CSS to animate size changes.
--positioner-widthnumberThe width of the tooltip's positioner. It is important to set width to this value when using CSS to animate size changes.
--transform-originstringThe coordinates that this element is anchored to. Used for animations and transitions.

A container for the tooltip contents. Renders a <div> element.

Popup Props:

PropTypeDefaultDescription
classNamestring | ((state: Tooltip.Popup.State) => string | undefined)-CSS class applied to the element, or a function that returns a class based on the component's state.
styleReact.CSSProperties | ((state: Tooltip.Popup.State) => React.CSSProperties | undefined)-Style applied to the element, or a function that returns a style object based on the component's state.
renderReactElement | ((props: HTMLProps, state: Tooltip.Popup.State) => ReactElement)-Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

Popup Data Attributes:

AttributeTypeDescription
data-open-Present when the tooltip is open.
data-closed-Present when the tooltip is closed.
data-align'start' | 'center' | 'end'Indicates how the popup is aligned relative to specified side.
data-instant'delay' | 'dismiss' | 'focus'Present if animations should be instant.
data-side'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start'Indicates which side the popup is positioned relative to the trigger.
data-starting-style-Present when the tooltip begins animating in.
data-ending-style-Present when the tooltip is animating out.

Arrow

Displays an element positioned against the tooltip anchor. Renders a <div> element.

Arrow Props:

PropTypeDefaultDescription
classNamestring | ((state: Tooltip.Arrow.State) => string | undefined)-CSS class applied to the element, or a function that returns a class based on the component's state.
styleReact.CSSProperties | ((state: Tooltip.Arrow.State) => React.CSSProperties | undefined)-Style applied to the element, or a function that returns a style object based on the component's state.
renderReactElement | ((props: HTMLProps, state: Tooltip.Arrow.State) => ReactElement)-Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

Arrow Data Attributes:

AttributeTypeDescription
data-open-Present when the tooltip is open.
data-closed-Present when the tooltip is closed.
data-uncentered-Present when the tooltip arrow is uncentered.
data-align'start' | 'center' | 'end'Indicates how the popup is aligned relative to specified side.
data-instant'delay' | 'dismiss' | 'focus'Present if animations should be instant.
data-side'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start'Indicates which side the popup is positioned relative to the trigger.

Viewport

A viewport for displaying content transitions. This component is only required if one popup can be opened by multiple triggers, its content changes based on the trigger, and switching between them is animated. Renders a <div> element.

Viewport Props:

PropTypeDefaultDescription
childrenReact.ReactNode-The content to render inside the transition container.
classNamestring | ((state: Tooltip.Viewport.State) => string | undefined)-CSS class applied to the element, or a function that returns a class based on the component's state.
styleReact.CSSProperties | ((state: Tooltip.Viewport.State) => React.CSSProperties | undefined)-Style applied to the element, or a function that returns a style object based on the component's state.
renderReactElement | ((props: HTMLProps, state: Tooltip.Viewport.State) => ReactElement)-Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

Viewport Data Attributes:

AttributeTypeDescription
data-activation-direction`${'left' | 'right' | ''} ${'down' | 'up' | ''}`Indicates the direction from which the popup was activated. This can be used to create directional animations based on how the popup was triggered. Contains space-separated values for both horizontal and vertical axes.
data-current-Applied to the direct child of the viewport when no transitions are present or the new content when it's entering.
data-instant'delay' | 'dismiss' | 'focus'Present if animations should be instant.
data-previous-Applied to the direct child of the viewport that contains the exiting content when transitions are present.
data-transitioning-Indicates that the viewport is currently transitioning between old and new content.

Viewport CSS Variables:

VariableTypeDescription
--popup-height``The height of the parent popup. This variable is placed on the 'previous' container and stores the height of the popup when the previous content was rendered. It can be used to freeze the dimensions of the popup when animating between different content.
--popup-width``The width of the parent popup. This variable is placed on the 'previous' container and stores the width of the popup when the previous content was rendered. It can be used to freeze the dimensions of the popup when animating between different content.

Accessibility

  • The tooltip is a visual aid. Screen reader users get the trigger's aria-label, so write the two to match.
  • The tooltip opens on hover and on keyboard focus of the trigger.
  • Escape closes it. Outside press closes it. Pressing the trigger closes it, unless you set closeOnClick={false}.
  • The popup can be hovered without closing. Set disableHoverablePopup on the root to change that.
  • The trigger carries data-popup-open while the tooltip is open, and data-trigger-disabled when it is disabled.