Tooltip
FreeHover/click/focus/long-press tooltip with 12 placements, rich title · description · keys content, nine looks, tooltip groups, a controlled open, anchors and three animations — and a Pro twin that can be hovered, focused and follows the cursor.
import { SvTooltipComponent } from '@styloviz/overlays/tooltip';Demo & usage
Basic usage
Usage example — open the gallery for the full interactive demo.
An interactive demo for this component lives in the gallery.
Open live demoMore examples
Click trigger, custom width
<sv-tooltip text="Copied to clipboard" trigger="click" position="right" [maxWidth]="220"> <button>Copy</button> </sv-tooltip>
Track visibility
<sv-tooltip text="Save changes" (visibleChange)="onTooltipToggle($event)"> <button>Save</button> </sv-tooltip>
Inside a table cell or card — portalled by default
<!-- The bubble renders in a body portal positioned by measurement, so an ancestor with overflow: hidden cannot clip it: it flips when the preferred side does not fit and is clamped to the viewport. [portal]="false" keeps it inside the trigger wrapper instead. --> <td class="overflow-hidden"> <sv-tooltip text="Unpaid since 12 May" position="top"> <button>Overdue</button> </sv-tooltip> </td>
Explaining a disabled control
<!-- A natively disabled button fires no pointer events and takes no focus, so a plain tooltip on it never appears. The preset takes the dead control out of hit-testing and gives the wrapper the tab stop. Prefer aria-disabled="true" when the control is yours - it needs none of this. Never use the preset around an ENABLED control. --> <sv-tooltip text="Only admins can delete projects" [forDisabledControl]="true"> <button disabled>Delete</button> </sv-tooltip>
When to use
Revealing a short, supplementary hint on hover/focus of a control. Explaining icon-only buttons or truncated labels. For rich, interactive content use a Popover (a hint with one link in it is `sv-tooltip-pro` with `[interactive]`); for persistent info, inline text.
Async states
None — this component has nothing to load, so it has no loading, empty or error state to drive.
Inputs
| Name | Type | Default | Description |
|---|---|---|---|
| text | string | '' | Tooltip text content. |
| position | TooltipPosition | 'top' | Position relative to the trigger. |
| variant | TooltipVariant | 'dark' | Color variant. |
| size | TooltipSize | 'md' | Size — controls font and padding. |
| trigger | TooltipTrigger | 'hover' | What triggers the tooltip. |
| maxWidth | number | null | 240 | Max width of the tooltip bubble (px); the text wraps at it. `null` keeps the bubble on one line however long the text is. |
| delay | number | 0 | Delay before showing (ms). |
| disabled | boolean | false | Whether the tooltip is disabled. |
| customClass | string | '' | Extra CSS classes merged onto the tooltip bubble. |
| portal | boolean | true | Render the bubble in a `<body>` portal, positioned by measurement — on by default. The in-place bubble clips: an absolutely positioned child is clipped by any ancestor with `overflow: hidden` — every table cell, card and scroll area in a dashboard — and it is placed by CSS classes alone, so it cannot see the viewport edge. The portal moves the bubble to the end of `<body>` and positions it with `svPositionAnchored` (the arithmetic Popover and Dropdown Menu use): it escapes the clip, flips when it does not fit, and is clamped to the viewport. `[portal]="false"` keeps the bubble inside the trigger wrapper, for a host that styles it by its position in the DOM. It was the default in earlier versions. |
| flip | boolean | true | Flip to the opposite side when the preferred one does not fit. Only meaningful when portalled (the default) — the in-place path has no measurement to decide with. |
| offset | number | 8 | Gap between trigger and bubble, in px, when portalled. Matches the `mb-2` / `mt-2` the in-place path uses, so `[portal]="false"` does not move the bubble. |
| fullWidth | boolean | false | Stretch the trigger wrapper to the width of its container. The wrapper is `inline-flex` by default, which is right for a word, an icon or a button — it hugs whatever it wraps. It is wrong the moment the trigger is a card in a grid or flex row: the wrapper becomes the track item and shrinks to its content, so the card does not fill its cell. Set this to lay the wrapper out as a full-width block instead. |
| forDisabledControl | boolean | false | Make the tooltip work over a control the browser has `disabled`. A disabled control fires no pointer events and takes no focus, so the tooltip explaining WHY it is disabled is the one tooltip in the kit that could never appear — and it is also the one users most need. The browser does not dispatch mouse events whose target is a disabled form control, so nothing reaches this wrapper either; and the control is out of the tab order, so the keyboard path is gone as well. What this does is two lines and both are necessary: the projected content gets `pointer-events: none`, which takes the disabled control out of hit-testing so hover and tap land on the WRAPPER; and the wrapper takes `tabindex="0"`, so the explanation is reachable by keyboard at all. `aria-describedby` already lives on the wrapper, so a screen-reader user who lands there hears the reason. Prefer `aria-disabled="true"` over `disabled` and you need none of this. A control marked `aria-disabled` stays focusable and keeps firing pointer events — it is announced as unavailable, your handler ignores the click, and every tooltip path works untouched. This preset is for the control you cannot change: a third-party component, or markup that is not yours. Do NOT set it around an ENABLED control. `pointer-events: none` applies to whatever is projected, so the control's own clicks stop working. Dev mode warns when the projected content does not look disabled. |
| title | string | '' | A bold first line above `text`, which becomes the description. |
| kbd | readonly string[] | [] | Keys to show on the bubble's end — a shortcut, drawn with `sv-kbd`. |
| arrow | boolean | true | Draw the arrow pointing at the trigger. |
| icon | string | '' | An icon before the content — a `@styloviz/icons` name. |
| status | TooltipStatus | null | null | A coloured status dot before the content. |
| open | boolean | undefined | undefined | Controlled visibility (two-way). Unbound, the tooltip shows and hides on its trigger. Bound, the trigger only REQUESTS — through `openChange` — and the bubble follows `open`, so a host can drive it: a slider showing its value while dragging, a guided tour. |
| anchor | Element | TooltipPoint | null | null | Position against this element or viewport point instead of the trigger — a slider's thumb, a chart's crosshair. Implies the portal. |
| touch | TooltipTouch | 'tap' | What a touch does where nothing can hover: tap to toggle, long-press, or nothing. |
| animation | TooltipAnimation | 'scale' | How the bubble enters and leaves; instant under reduced motion. |
Outputs
| Event | Payload type | Description |
|---|---|---|
| openChange | boolean | A visibility change asked for by the trigger — the controlled `open` decides. |
| visibleChange | boolean | Emitted whenever the tooltip's visibility changes (true = shown, false = hidden). |
<sv-tooltip-pro>
Also in this family — SvTooltipProComponent from @styloviz-pro/overlays.
Async states
None — this component has nothing to load, so it has no loading, empty or error state to drive.
Inputs
| Name | Type | Default | Description |
|---|---|---|---|
| text | string | '' | The tooltip's text — or its description, under a `title`. |
| position | TooltipPosition | 'top' | Where the bubble sits: one of the 12 placements. |
| variant | TooltipVariant | 'dark' | The bubble's look. |
| size | TooltipSize | 'md' | Bubble size: padding and type. |
| trigger | TooltipTrigger | 'hover' | What shows it: hover (and focus), click, or focus only. |
| maxWidth | number | null | 240 | Width cap in px; `null` keeps it on one line. |
| delay | number | 0 | Delay before it shows, in ms. |
| disabled | boolean | false | Switch the tooltip off — the trigger stays, the bubble never shows. |
| customClass | string | '' | Extra classes for the bubble. |
| portal | boolean | true | Render the bubble in a body portal (never clipped); `false` keeps it in place. |
| flip | boolean | true | Flip to the other side when it does not fit (portalled). |
| offset | number | 8 | Gap between trigger and bubble, in px. |
| fullWidth | boolean | false | Stretch the trigger wrapper to the full width. |
| forDisabledControl | boolean | false | Explain a disabled control (the wrapper takes the tab stop). |
| title | string | '' | A bold first line above `text`. |
| kbd | readonly string[] | [] | Keys to show on the bubble's end. |
| arrow | boolean | true | Draw the arrow. |
| icon | string | '' | An icon before the content. |
| status | TooltipStatus | null | null | A status dot before the content. |
| open | boolean | undefined | undefined | Controlled visibility (two-way). Bound, the trigger only requests through `openChange` and the bubble follows `open`. |
| anchor | Element | TooltipPoint | null | null | Position against this element or point instead of the trigger. |
| touch | TooltipTouch | 'tap' | What a touch does where nothing can hover. |
| animation | TooltipAnimation | 'scale' | How the bubble enters and leaves. |
| interactive | boolean | false | The bubble can be hovered, focused and used: it stays while the pointer travels onto it (within `hideDelay`) and while focus is inside it; Tab from the trigger moves into it. Implies the portal. |
| hideDelay | number | 200 | How long an interactive bubble waits before hiding once the pointer leaves, in ms. |
| followCursor | boolean | false | The bubble follows the pointer across the trigger. Implies the portal. |
Outputs
| Event | Payload type | Description |
|---|---|---|
| visibleChange | boolean | The bubble appeared or went away. |
| openChange | boolean | A visibility change asked for — the controlled `open` decides. |
Customization & theming
Twelve placements (`top`, `top-start` … `right-end`; `start`/`end` mirror in RTL), nine looks (dark · light · primary · danger · success · warning · inverted · glass · value) and three sizes (sm · md · lg). Rich content: a `title` above the text, `kbd` keys, an `icon`, a `status` dot, or your own markup in a `[svTooltipContent]` template; `[arrow]` toggles the pointer and `animation` is `fade` · `scale` · `shift`. `[svTooltipGroup]` on a toolbar: the first tooltip waits for `groupDelay`, the next one along shows at once (within `skipDelay`), and only one is open at a time. `[open]` controls it from outside; `[anchor]` points it at another element or a viewport point. Hover, click or focus triggers — and on a pointer that cannot hover, a `hover` tooltip becomes tap-to-toggle by itself, with the show delay skipped and a press anywhere else dismissing it (`touch="hold"` makes it a long-press instead, `touch="off"` leaves it out on touch). A `focus` or `click` trigger is left alone. Configurable show/hide delay. `customClass` on the bubble; `visibleChange` output. The bubble renders in a `<body>` portal positioned by measurement (the default; `[portal]="false"` keeps it in place) — the same arithmetic Popover and Dropdown Menu use. It escapes an `overflow: hidden` ancestor (every table cell, card and scroll area), flips with `[flip]`, is clamped to the viewport, keeps its arrow over the trigger when clamped, and re-anchors on scroll of any ancestor. A portalled tooltip paints in the ambient tooltip band, so it clears a dialog it appears inside — and it never becomes the surface Escape closes. `[forDisabledControl]="true"` — the disabled-control preset: the projected control gets `pointer-events: none` so hover and tap land on the wrapper, and the wrapper becomes a tab stop described by the tooltip from the start (Enter/Space toggle a `click` tooltip there). Dev mode warns when the projected content is not actually disabled. Pro (`sv-tooltip-pro`): `[interactive]` keeps the bubble open while the pointer is on it (after `hideDelay`) or focus is inside, so links in it work and Tab from the trigger goes in; `[followCursor]` makes it ride with the pointer over a chart or a timeline.
Best practices
Do: Keep tooltip text to a few words — it's a hint, not documentation. Do: Ensure it appears on keyboard focus, not hover alone (it does). Do: Leave the portal on (the default) whenever the trigger sits inside a table cell, a card, or anything that scrolls or hides its overflow; `[portal]="false"` puts the bubble back inside the trigger wrapper, where that ancestor clips it and a viewport edge cuts it off. Don't: Don't hide essential information in a tooltip — many users never trigger it, and a touch user only finds it by tapping. If the text is needed to complete the task, put it in visible helper text, or in a click-opened Popover (`[interactive]="false"` for a read-only note). Don't: Don't put interactive content in a `sv-tooltip` — links, buttons, form fields. Its bubble is `pointer-events-none`, so even markup projected through `[svTooltipContent]` cannot be clicked: that is structural, not a guideline. A hint with one link in it is `sv-tooltip-pro` with `[interactive]="true"`; anything more is a Popover.
Accessibility
Shows on keyboard focus, not just hover, and emits `visibleChange` on every transition. Associated via aria-describedby; dismissible with Esc. It works on touch, which a hover tooltip does not — worse, it half-works: mobile browsers synthesise `mouseenter` on tap, so the tap meant to activate the trigger raises the tooltip over the control just pressed, and with no `mouseleave` coming it stays there. Where hovering is unavailable the tooltip switches to tap-to-toggle, skips the delay (a tap is deliberate), and dismisses on a press elsewhere — there is no `mouseleave` on a finger and no Escape key on a phone. It follows a pointer that changes mid-session, because a convertible laptop folds. Forced colours: every bubble — the glass one included — keeps a `CanvasText` edge, because forced colours repaint its fill as Canvas and remove its ring.
Feedback on Tooltip
Spotted a gap in this page, or something that didn't work as described? Comments are GitHub Discussions in the public styloviz/community repo, so posting needs a GitHub account.