Skip to main content

Tooltip

Show supplemental, non-interactive information on hover or focus.

Props
Slots

Anatomy#

Tooltip [component; no DOM]
├── Tooltip.Trigger [part; slot=trigger]
└── positioner [internal]
    └── Tooltip.Content [part; slot=content]
        └── kbds [slot]
            └── item [internal]

Content is portaled into an internal positioning wrapper.

Usage#

Use Tooltip for supplemental information on hover or focus. Use Popover when the content is interactive. Use Dialog or Sheet for a task that should take over the page. Do not rely on tooltip text as the only accessible name of a control: the trigger needs its own name, such as visible text or aria-label. The trigger references the content through aria-describedby.

import { Button, Tooltip } from 'moraine'

export function Example() {
  return (
    <Tooltip>
      <Tooltip.Trigger as={Button}>Save</Tooltip.Trigger>
      <Tooltip.Content>Save changes</Tooltip.Content>
    </Tooltip>
  )
}

Text and content#

Pass plain text or JSX as children of Tooltip.Content. String children render in the text slot; other children render directly inside the content. Set variant="invert" on Tooltip to flip the colors.

<Tooltip>
  <Tooltip.Trigger as={Button}>Deploy History</Tooltip.Trigger>
  <Tooltip.Content>View project deployment history and logs</Tooltip.Content>
</Tooltip>

Triggering and shortcuts#

Tooltip opens from pointer hover and keyboard focus. kbds displays shortcut notation after the hint; it does not register that shortcut. Names such as command, ctrl, shift, and meta render as symbols. Set kbdVariant on Tooltip.Content to default, outline, or invert. When omitted, keycaps use invert if the tooltip’s variant is invert, and default otherwise.

<Tooltip>
  <Tooltip.Trigger as={Button} leading="i-lucide:save">
    Save
  </Tooltip.Trigger>
  <Tooltip.Content kbds={['command', 's']} kbdVariant="outline">
    Save changes
  </Tooltip.Content>
</Tooltip>

Delays and grouped tooltips#

openDelay (default 600 ms) waits before opening from hover or focus, and closeDelay (default 200 ms) lets the pointer move from the trigger onto the content without closing it. Set either to 0 for no delay. After one tooltip closes, any tooltip in the same document opens without openDelay for skipDelay (default 300 ms), so moving across a toolbar does not wait on every button; set it to 0 to disable the grace period. placement defaults to 'top', and gutter defaults to 4 px.

Control the open state with open and onOpenChange, or start open with defaultOpen. disabled keeps the tooltip closed, and forceMount keeps its content in the DOM while closed.

Keyboard interaction#

Moving keyboard focus to the trigger opens the tooltip, and blurring it closes the tooltip. Pressing the trigger dismisses the tooltip so a click does not leave it open.

Examples#

Explain a labeled command#

Hover or focus Deploy History for a longer description. The button already has a visible name.

import { Button, Tooltip } from 'moraine'

export function HintsUsage() {
  return (
    <div class="flex gap-4 items-center">
      <Tooltip>
        <Tooltip.Trigger as={Button} variant="outline">
          Deploy History
        </Tooltip.Trigger>
        <Tooltip.Content>View project deployment history and logs</Tooltip.Content>
      </Tooltip>
    </div>
  )
}

Show a save shortcut#

kbds is display-only. Pair it with a labeled Save control.

import { Button, Tooltip } from 'moraine'

export function ShortcutsUsage() {
  return (
    <div class="flex gap-4 items-center">
      <Tooltip>
        <Tooltip.Trigger as={Button} leading="i-lucide:save">
          Save
        </Tooltip.Trigger>
        <Tooltip.Content kbds={['command', 's']} kbdVariant="outline">
          Save changes
        </Tooltip.Content>
      </Tooltip>
    </div>
  )
}

Label editor toolbar shortcuts#

Keep icon-only controls named with aria-label. Each tooltip repeats the command and shows its shortcut.

import { Button, Tooltip } from 'moraine'

export function KeyboardShortcuts() {
  return (
    <div class="p-2 b-1 b-border rounded-xl bg-card flex flex-wrap gap-2 items-center">
      <Tooltip>
        <Tooltip.Trigger as={Button} variant="outline" size="sm" leading="i-lucide:save">
          Save
        </Tooltip.Trigger>
        <Tooltip.Content kbds={['⌘', 'S']}>Save changes</Tooltip.Content>
      </Tooltip>

      <Tooltip>
        <Tooltip.Trigger
          as={Button}
          variant="ghost"
          size="sm"
          leading="i-lucide:bold"
          aria-label="Bold"
        />
        <Tooltip.Content kbds={['⌘', 'B']}>Bold formatting</Tooltip.Content>
      </Tooltip>

      <Tooltip>
        <Tooltip.Trigger
          as={Button}
          variant="ghost"
          size="sm"
          leading="i-lucide:italic"
          aria-label="Italic"
        />
        <Tooltip.Content kbds={['⌘', 'I']}>Italic formatting</Tooltip.Content>
      </Tooltip>

      <Tooltip>
        <Tooltip.Trigger
          as={Button}
          variant="ghost"
          size="sm"
          leading="i-lucide:code"
          aria-label="Code"
        />
        <Tooltip.Content kbds={['⌘', 'E']}>Insert Code Block</Tooltip.Content>
      </Tooltip>

      <Tooltip>
        <Tooltip.Trigger
          as={Button}
          variant="ghost"
          size="sm"
          leading="i-lucide:search"
          aria-label="Search"
        />
        <Tooltip.Content kbds={['⌘', 'K']}>Quick Search</Tooltip.Content>
      </Tooltip>
    </div>
  )
}

API Reference#

Attributes#

Attributes
data-closed
Slot: tooltip-triggertooltip-content
Description: Present when disclosure or transition content is closed.
data-disabled
Slot: tooltip-trigger
Description: Present when the component, slot, or item is disabled.
data-expanded
Slot: tooltip-triggertooltip-content
Description: Present when the panel, accordion, or menu is expanded.
data-align
Slot: tooltip-content
Description: Stores the resolved alignment of positioned content.
data-instant-motion
Slot: tooltip-content
Description: Present when enter and exit motion should complete immediately.
data-side
Slot: tooltip-content
Description: Stores the resolved floating or drawer content side.

Props#

Tooltip#

Prop

Trigger#

Renders a <button> element by default.

Prop

Content#

Props for the Tooltip component. Renders a <div> element by default.

Prop