icon

Morainev0.5.0

Tooltip
overlaystooltip

Tooltip

Hover-triggered informational overlay anchored to a trigger element.

Import#

import { Tooltip } from 'moraine'

Slot Structure#

Wrapper trigger with a floating content portal containing text and optional keyboard hints.

trigger
└── content (portal)
├── text (optional)
└── kbds (optional)
└── kbd (×n)

Examples#

Placements#

Tooltip positioned on each side.

function Placements() {
const PLACEMENTS = ['top', 'right', 'bottom', 'left'] as const
return (
<div class="flex flex-wrap gap-4 items-center">
<For each={PLACEMENTS}>
{(placement) => (
<Tooltip text={`Tooltip on ${placement}`} placement={placement}>
<Button variant="outline">{placement}</Button>
</Tooltip>
)}
</For>
</div>
)
}

Trigger Types#

Tooltip on buttons and inline text.

function TriggerTypes() {
return (
<div class="flex flex-wrap gap-4 items-center">
<Tooltip text="Button trigger">
<Button>Hover me</Button>
</Tooltip>
<p class="text-sm text-foreground">
Hover over this{' '}
<Tooltip text="Inline tooltip">
<span class="font-medium underline cursor-help">underlined text</span>
</Tooltip>{' '}
to see a tooltip.
</p>
</div>
)
}

Keyboard Shortcuts#

Display keyboard shortcut hints alongside tooltip text.

function KeyboardShortcuts() {
return (
<div class="flex flex-wrap gap-4 items-center">
<Tooltip text="Save" kbds={['Ctrl', 'S']} open>
<Button variant="outline" leading="i-lucide-save">
Save
</Button>
</Tooltip>
<Tooltip text="Undo" kbds={['Ctrl', 'Z']}>
<Button variant="outline" leading="i-lucide-undo">
Undo
</Button>
</Tooltip>
<Tooltip text="Search" kbds={['Ctrl', 'K']}>
<Button variant="outline" leading="i-lucide-search">
Search
</Button>
</Tooltip>
</div>
)
}

Text Only vs Shortcuts Only#

Content variations.

function TextOnlyVsShortcutsOnly() {
const [invert, setInvert] = createSignal(false)
return (
<div class="flex flex-wrap gap-4 items-center">
<Tooltip invert={invert()} text="Just a message">
<Button variant="outline">Text only</Button>
</Tooltip>
<Tooltip invert={invert()} kbds={['Ctrl', 'Shift', 'P']}>
<Button variant="outline">Shortcuts only</Button>
</Tooltip>
<Tooltip invert={invert()} text="Command palette" kbds={['Ctrl', 'Shift', 'P']}>
<Button variant="outline">Both</Button>
</Tooltip>
<Switch checked={invert()} onChange={setInvert} label="Invert" />
</div>
)
}

API Reference#

Attributes#

Slotcontent6 attributes
Tooltip bubble positioned next to its trigger.

CSS Variables

1
CSS VariableDescription
--mo-popper-content-transform-origin
CSS custom property exposed by this slot.

Data Attributes

1
Data AttributeDescription
data-placement
State or slot attribute exposed for styling hooks and selectors.

ARIA Attributes

4
ARIA AttributeDescription
aria-describedby
References descriptive text associated with the control.
aria-labelledby
References the element that labels the control or region.
aria-modal
Identifies modal content that traps interaction outside the dialog.
role
Defines the semantic role exposed to assistive technology.

Props#

PropTypeDefaultDescription
childrenJSX.Element
The reference element that triggers the tooltip.
classClassValue
Class applied to the component root or trigger element.
classesTooltipT.Classes | undefined
closeDelaynumber | undefined200
Delay in milliseconds before closing after leaving trigger or content.
defaultOpenboolean | undefined
disabledboolean | undefined
forceMountboolean | undefined
idstring | undefined
instantOpenDelaynumber | undefined300
Delay in milliseconds to skip the open delay for the next trigger after closing.
invertboolean | undefined
kbdsstring[] | undefined
Keyboard shortcuts to display next to the text.
onOpenChange((open: boolean) => void) | undefined
openboolean | undefined
openDelaynumber | undefined600
Delay in milliseconds before opening on hover or focus.
placementPlacement | undefined
refJSX.HTMLElementTags["span"] extends { ref?: infer Ref; } ? Ref : never | undefined
side"bottom" | "top" | "right" | "left" | undefined
styleJSX.CSSProperties | undefined
stylesTooltipT.Styles | undefined
textJSX.Element
Primary text content or element to display.