# Tooltip Primitive

Tooltip is a Starwind Runtime primitive in the presence-floating-overlay contract family.
## Anatomy
### Astro
Use the Astro primitive adapter to render Tooltip anatomy with the Runtime wiring included.
```astro
---
import { Tooltip } from "@starwind-ui/astro/tooltip";
---

<Tooltip.Root>
  <Tooltip.Trigger>Hover me</Tooltip.Trigger>
  <Tooltip.Positioner>
    <Tooltip.Popup>
      <Tooltip.Arrow />
    </Tooltip.Popup>
  </Tooltip.Positioner>
</Tooltip.Root>
```

### React
Use the React primitive adapter when Tooltip state participates in React rendering.
```tsx
import { Tooltip } from "@starwind-ui/react/tooltip";

export function Example() {
  return (
    <Tooltip.Root>
      <Tooltip.Trigger>Hover me</Tooltip.Trigger>
      <Tooltip.Positioner>
        <Tooltip.Popup>
          <Tooltip.Arrow />
        </Tooltip.Popup>
      </Tooltip.Positioner>
    </Tooltip.Root>
  );
}
```

### HTML
Render the Tooltip data-sw-* contract yourself, then initialize createTooltip.
```html
<div data-sw-tooltip>
  <button data-sw-tooltip-trigger type="button">Hover me</button>
  <div data-sw-tooltip-positioner>
    <div data-sw-tooltip-popup role="tooltip" hidden>
      <div data-sw-tooltip-arrow></div>
    </div>
  </div>
</div>

<script type="module">
  import { createTooltip } from "@starwind-ui/runtime/tooltip";

  const root = document.querySelector("[data-sw-tooltip]");
  if (root) {
    createTooltip(root);
  }
</script>
```
## Floating Behavior
| Fact | Value |
| --- | --- |
| Anchor part | trigger |
| Positioner part | positioner |
| Popup part | popup |
| Portal part | portal |
| Option props | side, align, sideOffset, avoidCollisions |
## API Reference
### Root
The main element that owns the Tooltip Runtime instance.
| Fact | Value |
| --- | --- |
| Default element | `div` |
| Discovery hook | `data-sw-tooltip` |
| Role | - |
#### Props
| Prop | Type | Default | Kind | Description |
| --- | --- | --- | --- | --- |
| open | `boolean` | - | control | Controls whether Tooltip is open. |
| defaultOpen | `boolean` | false | control | Sets whether Tooltip starts open. |
| closeDelay | `number` | 200 | option | Sets how long Tooltip waits before closing. |
| closeOnEscape | `boolean` | true | option | Closes Tooltip when Escape is pressed. |
| closeOnOutsideInteract | `boolean` | true | option | Closes Tooltip when the user interacts outside it. |
| disabled | `boolean` | false | option | Disables the Root part. |
| disableHoverableContent | `boolean` | false | option | Configures the disable hoverable content option for the Root part. |
| openDelay | `number` | 200 | option | Sets how long Tooltip waits before opening. |
| onOpenChange | `(open: boolean, details: TooltipOpenChangeDetails) => void` | - | callback | Runs when Tooltip opens or closes. |
#### Data Attributes
| Attribute | Source | Value | Description |
| --- | --- | --- | --- |
| `data-sw-tooltip` | runtime | - | Marks the Root part so Starwind Runtime can find it. |
| `data-default-open` | prop | - | Reflects the default open prop on the Root part. |
| `data-close-delay` | prop | - | Reflects the close delay prop on the Root part. |
| `data-close-on-escape` | prop | - | Reflects the close on escape prop on the Root part. |
| `data-close-on-outside-interact` | prop | - | Reflects the close on outside interact prop on the Root part. |
| `data-content-hoverable` | prop | - | Reflects the content hoverable prop on the Root part. |
| `data-disabled` | prop | - | Reflects the disabled prop on the Root part. |
| `data-open-delay` | prop | - | Reflects the open delay prop on the Root part. |
| `data-state` | state | - | Reflects the current state on the Root part. |
#### State
| State | Value Type | Controlled Prop | Default Prop | Initial Attribute | Runtime Getter | Runtime Setter | Description | State Control Support |
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
| open | `boolean` | open | defaultOpen | `data-default-open` | `getOpen` | `setOpen` | Tracks whether Tooltip is open. | React supports controlled and default state with open and defaultOpen props. Runtime/HTML reads initial state from data-default-open, emits starwind:open-change, and updates with setOpen. Astro adapters render initial/default state, but do not expose reactive controlled-state props for this state. |
#### Events
| Event | Callback | DOM Event | Value | Details | Timing | Cancelable | Description |
| --- | --- | --- | --- | --- | --- | --- | --- |
| openChange | onOpenChange | starwind:open-change | open: `boolean` | TooltipOpenChangeDetails | before-state-commit | Yes | Fires when Tooltip opens or closes. |
#### Runtime Setters
| Method | Target | Options | Suppresses Emit | Description |
| --- | --- | --- | --- | --- |
| `setOpen` | state: open | emit: false | Yes | Opens or closes Tooltip from Runtime code. |
| `setDisabled` | prop: disabled | - | No | Updates whether Tooltip is disabled from Runtime code. |
#### Refs
| Part | Public |
| --- | --- |
| root | Yes |
#### Initial Markup
| Attributes | Reason |
| --- | --- |
| `data-sw-tooltip`, `data-default-open`, `data-close-delay`, `data-close-on-escape`, `data-close-on-outside-interact`, `data-content-hoverable`, `data-disabled`, `data-open-delay`, `data-state` | The tooltip root needs timing, dismissal, disabled, hoverability, and initial state markers before hydration. |
#### Presence
| Fact | Value |
| --- | --- |
| Initial hidden | No |
| Unmount policy | runtime-owned |
| Keep mounted prop | - |

### Trigger
The control that opens, closes, or targets the Tooltip content.
| Fact | Value |
| --- | --- |
| Default element | `button` |
| Discovery hook | `data-sw-tooltip-trigger` |
| Role | - |
#### Props
| Prop | Type | Default | Kind | Description |
| --- | --- | --- | --- | --- |
| asChild | `boolean` | - | rendering | Merges behavior onto your child element instead of rendering the default Trigger element. |
#### Data Attributes
| Attribute | Source | Value | Description |
| --- | --- | --- | --- |
| `data-sw-tooltip-trigger` | runtime | - | Marks the Trigger part so Starwind Runtime can find it. |
| `data-as-child` | prop | - | Reflects the as child prop on the Trigger part. |
| `data-disabled` | prop | - | Reflects the disabled prop on the Trigger part. |
| `data-state` | state | - | Reflects the current state on the Trigger part. |
#### Refs
| Part | Public |
| --- | --- |
| trigger | Yes |
#### asChild
| Part | Merged Props |
| --- | --- |
| trigger | data, ref |
#### Initial Markup
| Attributes | Reason |
| --- | --- |
| `data-sw-tooltip-trigger`, `data-as-child`, `data-disabled`, `aria-disabled`, `data-state`, `disabled`, `type` | Triggers need disabled state and initial closed state before pointer/focus listeners attach. |

### Portal
Moves Tooltip overlay content to the document body when needed.
| Fact | Value |
| --- | --- |
| Default element | `div` |
| Discovery hook | `data-sw-tooltip-portal` |
| Role | - |
#### Data Attributes
| Attribute | Source | Value | Description |
| --- | --- | --- | --- |
| `data-sw-tooltip-portal` | runtime | - | Marks the Portal part so Starwind Runtime can find it. |
#### Refs
| Part | Public |
| --- | --- |
| portal | Yes |

### Positioner
Positions the Tooltip content relative to its trigger.
| Fact | Value |
| --- | --- |
| Default element | `div` |
| Discovery hook | `data-sw-tooltip-positioner` |
| Role | - |
#### Props
| Prop | Type | Default | Kind | Description |
| --- | --- | --- | --- | --- |
| side | `"top" \| "right" \| "bottom" \| "left"` | "top" | option | Sets the preferred side for Tooltip content. |
| align | `"start" \| "center" \| "end"` | "center" | option | Sets how Tooltip content aligns to its trigger. |
| sideOffset | `number` | 8 | option | Sets the distance between Tooltip content and its trigger. |
| avoidCollisions | `boolean` | true | option | Allows Tooltip content to shift or flip to stay visible. |
#### Data Attributes
| Attribute | Source | Value | Description |
| --- | --- | --- | --- |
| `data-sw-tooltip-positioner` | runtime | - | Marks the Positioner part so Starwind Runtime can find it. |
| `data-state` | state | - | Reflects the current state on the Positioner part. |
| `data-side` | prop | - | Reflects the side prop on the Positioner part. |
| `data-align` | prop | - | Reflects the align prop on the Positioner part. |
| `data-side-offset` | prop | - | Reflects the side offset prop on the Positioner part. |
| `data-avoid-collisions` | prop | - | Reflects the avoid collisions prop on the Positioner part. |
#### Refs
| Part | Public |
| --- | --- |
| positioner | Yes |
#### Initial Markup
| Attributes | Reason |
| --- | --- |
| `data-sw-tooltip-positioner`, `data-state`, `data-side`, `data-align`, `data-side-offset`, `data-avoid-collisions` | The positioner carries initial placement hints used by the shared floating runtime. |

### Popup
The floating content container for Tooltip.
| Fact | Value |
| --- | --- |
| Default element | `div` |
| Discovery hook | `data-sw-tooltip-popup` |
| Role | `tooltip` |
#### Props
| Prop | Type | Default | Kind | Description |
| --- | --- | --- | --- | --- |
| side | `"top" \| "right" \| "bottom" \| "left"` | "top" | option | Sets the preferred side for Tooltip content. |
| align | `"start" \| "center" \| "end"` | "center" | option | Sets how Tooltip content aligns to its trigger. |
| sideOffset | `number` | 8 | option | Sets the distance between Tooltip content and its trigger. |
| avoidCollisions | `boolean` | true | option | Allows Tooltip content to shift or flip to stay visible. |
#### Data Attributes
| Attribute | Source | Value | Description |
| --- | --- | --- | --- |
| `data-sw-tooltip-popup` | runtime | - | Marks the Popup part so Starwind Runtime can find it. |
| `data-state` | state | - | Reflects the current state on the Popup part. |
| `data-side` | prop | - | Reflects the side prop on the Popup part. |
| `data-align` | prop | - | Reflects the align prop on the Popup part. |
| `data-side-offset` | prop | - | Reflects the side offset prop on the Popup part. |
| `data-avoid-collisions` | prop | - | Reflects the avoid collisions prop on the Popup part. |
#### Refs
| Part | Public |
| --- | --- |
| popup | Yes |
#### Initial Markup
| Attributes | Reason |
| --- | --- |
| `data-sw-tooltip-popup`, `role`, `data-state`, `data-side`, `data-align`, `data-side-offset`, `data-avoid-collisions`, `hidden` | The tooltip popup starts hidden with tooltip semantics and initial placement hints before hydration. |
#### Presence
| Fact | Value |
| --- | --- |
| Initial hidden | Yes |
| Unmount policy | runtime-owned |
| Keep mounted prop | - |

### Arrow
The arrow element that visually points to the trigger.
| Fact | Value |
| --- | --- |
| Default element | `div` |
| Discovery hook | `data-sw-tooltip-arrow` |
| Role | - |
#### Data Attributes
| Attribute | Source | Value | Description |
| --- | --- | --- | --- |
| `data-sw-tooltip-arrow` | runtime | - | Marks the Arrow part so Starwind Runtime can find it. |
| `data-state` | state | - | Reflects the current state on the Arrow part. |
#### Refs
| Part | Public |
| --- | --- |
| arrow | Yes |
#### Initial Markup
| Attributes | Reason |
| --- | --- |
| `data-sw-tooltip-arrow`, `data-state` | The arrow receives state and placement updates from the floating runtime. |
## Runtime API
| Fact | Value |
| --- | --- |
| Factory | [`createTooltip`](/docs/runtime/#create-tooltip) |
| Import | `@starwind-ui/runtime/tooltip` |
| Root part | root |
| Option props | closeDelay, closeOnEscape, closeOnOutsideInteract, defaultOpen, disabled, disableHoverableContent, onOpenChange, open, openDelay |
| Option lifecycles | closeDelay: constructor-only, closeOnEscape: constructor-only, closeOnOutsideInteract: constructor-only, defaultOpen: constructor-only, disabled: setter-backed, disableHoverableContent: constructor-only, onOpenChange: constructor-only, open: setter-backed, openDelay: constructor-only |
## Related Styled Components
| Component | Relationship |
| --- | --- |
| [Tooltip](/docs/components/tooltip/) | Direct Primitive |
## Exports
| Group | Import | Exports |
| --- | --- | --- |
| Runtime | `@starwind-ui/runtime/tooltip` | `createTooltip` |
| Astro Primitive | `@starwind-ui/astro/tooltip` | `Tooltip`, `TooltipRoot`, `TooltipTrigger`, `TooltipPortal`, `TooltipPositioner`, `TooltipPopup`, `TooltipArrow` |
| React Primitive | `@starwind-ui/react/tooltip` | `Tooltip`, `TooltipRoot`, `TooltipTrigger`, `TooltipPortal`, `TooltipPositioner`, `TooltipPopup`, `TooltipArrow` |
## Canonical Names
| Kind | Name |
| --- | --- |
| namespace | `Tooltip` |
| runtime-factory | `createTooltip` |
| part | `Tooltip.Root` |
| part | `Tooltip.Trigger` |
| part | `Tooltip.Portal` |
| part | `Tooltip.Positioner` |
| part | `Tooltip.Popup` |
| part | `Tooltip.Arrow` |