Overlays
Tooltip A floating label that appears on hover or focus to provide additional context for an element.
npm pnpm yarn bun
npm install @morphos/overlays pnpm add @morphos/overlays yarn add @morphos/overlays bun add @morphos/overlays
import { Tooltip, TooltipTrigger, TooltipContent } from '@morphos/overlays'
@ Component ()
class MyComponent extends StatefulComponent {
@ State () tooltip = new Tooltip ()
render () {
return (
<>
< TooltipTrigger tooltip = { this .tooltip}>
Hover me
</ TooltipTrigger >
< TooltipContent tooltip = { this .tooltip}>
This is a tooltip
</ TooltipContent >
</>
)
}
}
Component Description TooltipRoot state manager. Owns open state, open/close timers, and the computed anchor position. TooltipTrigger<span> that shows the tooltip on mouseenter/focus and hides it on mouseleave/blur. Sets aria-describedby and data-open.TooltipContentRenders into a Portal, positioned with position: fixed. Sets role="tooltip" and data-open.
Prop Type Default Description openDelaynumber500Milliseconds to wait before opening. closeDelaynumber0Milliseconds to wait before closing. side"top" | "bottom" | "left" | "right""top"Which edge of the trigger the tooltip is placed against. align"start" | "center" | "end""center"Alignment of the tooltip along the trigger's perpendicular axis. sideOffsetnumber4Gap in pixels between the trigger and the tooltip. childrenChildren— Content — typically TooltipTrigger and TooltipContent.
Method Description show()Cancels any pending close, then opens the tooltip after openDelay ms (recomputing its position). hide()Cancels any pending open, then closes the tooltip after closeDelay ms.
Prop Type Default Description tooltipTooltip— The Tooltip instance this trigger controls. childrenChildren— The trigger element content. classstring— CSS class. idstring— HTML id.
Prop Type Default Description tooltipTooltip— The Tooltip instance this content belongs to. childrenChildren— Tooltip content. classstring— CSS class. idstring— HTML id. Falls back to an auto-generated id. aria-labelstring— Accessible label for the tooltip content.
Attribute Element When present data-openTooltipTriggerTooltip is visible data-openTooltipContent rootTooltip is visible
The tooltip opens and closes based on pointer and keyboard events on TooltipTrigger:
Event Action mouseenterOpens after openDelay ms mouseleaveCloses after closeDelay ms focusOpens after openDelay ms blurCloses after closeDelay ms
TooltipContent renders with role="tooltip" inside a Portal, so it is always appended to the
document body and avoids overflow clipping from parent containers. Its position is computed
with computeAnchorPosition() from @morphos/core, using TooltipTrigger's bounding rect and
the side/align/sideOffset props on Tooltip. Tooltip does not trap focus or lock scroll —
it is non-modal.
.morphos-tooltip-content {
z-index : 100 ;
max-width : 20 rem ;
padding : var ( --morphos-space-1 ) var ( --morphos-space-2 );
font-size : 0.8125 rem ;
background : var ( --morphos-color-text );
color : var ( --morphos-color-accent-text );
border-radius : var ( --morphos-radius-sm );
}