Components

Tooltip

A short label for a control on hover or keyboard focus

Import
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@nyte-ai/ui/tooltip";

A visible label and optional shortcut for a control with an accessible name. For longer content, use Preview card.

Usage

  • Pass the control to TooltipTrigger through render. Give the control its own aria-label, because the tooltip does not name it.
  • An icon-only Button also sets its label as the native title. Pass title={undefined} so only one tooltip appears.
  • TooltipContent keeps line breaks in its text.
  • Wrap the app once in TooltipProvider. A trigger's own delay or closeDelay overrides it.
  • Keep instructions and disabled reasons visible outside the tooltip.

Anatomy

<TooltipProvider>
  <Tooltip>
    <TooltipTrigger />
    <TooltipContent />
  </Tooltip>
</TooltipProvider>

Examples

import { Button } from "@nyte-ai/ui/button";
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@nyte-ai/ui/tooltip";

<TooltipProvider>
  <Tooltip>
    <TooltipTrigger
      render={<Button iconOnly icon="copy" aria-label="Copy output" title={undefined} />}
    />
    <TooltipContent>Copy output</TooltipContent>
  </Tooltip>
  <Tooltip>
    <TooltipTrigger
      render={<Button iconOnly icon="trash" aria-label="Delete session" title={undefined} />}
    />
    <TooltipContent>Delete session ⌘⌫</TooltipContent>
  </Tooltip>
</TooltipProvider>;

Props

TooltipContent takes xstyle, className, and style. Its className and style cannot be functions of state. See Theming. Tooltip and TooltipTrigger are Base UI's.

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

Tooltip

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.

TooltipTrigger

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.

TooltipContent

Renders the portal, positioner, and popup. Positioning props go to the positioner and the rest to the popup.

PropTypeDefault
side"top" | "bottom" | "left" | "right" | "inline-start" | "inline-end""bottom"
align"start" | "center" | "end""center"
sideOffsetnumber | OffsetFunction6
alignOffsetnumber | OffsetFunction
tintTint

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.

TooltipProvider

PropDefault
delay300
closeDelay100
timeout200

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--

Accessibility

  • Hover opens after delay. Keyboard focus opens at once.
  • Escape, an outside press, and a trigger click close it.
  • The popup appears without motion under prefers-reduced-motion: reduce.