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, or Dialog and 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 to default, outline, or invert. When omitted, keycaps use invert if the tooltip’s variant is invert, and default otherwise.

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

Delays and groups#

Configure timing and positioning on Tooltip:

  • openDelay (default 600 ms): waits before opening from hover or focus. Set to 0 for no delay.
  • closeDelay (default 200 ms): lets the pointer move from the trigger onto the content without closing it. Set to 0 for no delay.
  • skipDelay (default 300 ms): after one tooltip closes, any tooltip in the same document opens without openDelay during this window so moving across a toolbar does not wait on every button. Set to 0 to disable.
  • placement and gutter: default to 'top' and 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. Escape closes an open tooltip. Pressing the trigger dismisses the tooltip so a click does not leave it open.

Examples#

Basic#

Hover or focus a trigger to reveal supplementary text.

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

Keyboard shortcut#

Pass kbds to display shortcut hints alongside tooltip text.

import { Button, Tooltip } from 'moraine'

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

Toolbar group#

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 `Tooltip.Content`. Renders a <div> element by default.

Prop