Tooltip
Text tooltips with positions, arrow, colors and visibility controls.
When to use
Tooltip provides a short, non-interactive explanation of an action or text. The tooltip complements the available name, but should not be the only way to find out what the button does. For buttons, links, and fields within popup content, use Popover.
trigger and hint state
title contains text, value or Svelte snippet. children outputs the actual DOM trigger: a button, a link, or a suitable element of its own component. null and empty title disable explanations; numeric 0 is displayed.
| Problem | Setting | Example |
|---|---|---|
| Explain action | title, children |
Brief explanation |
| Select events | trigger |
Opening |
| Use your component | native control in snippet | Your trigger |
| Manage content cache | fresh, destroyOnHidden |
Cache |
| Update position | bind:ref, forceAlign |
Recalculation |
trigger supports hover/focus/click/contextMenu and an array of events. For the keyboard, provide focus and keep the name of the control itself accessible. mouseEnterDelay/mouseLeaveDelay are measured in seconds; focus/blur delays are configurable separately.
defaultOpen sets the initial opening. bind:open reflects the state of the application, onOpenChange reports the change. Don't count on hover as the only way to open for touch.
Position, pointer and container
placement supports twelve main and corner positions. autoAdjustOverflow can flip the popup; main directions also allow displacement along the edge of the viewport, corner directions remain snapped to the trigger edge. When correction is disabled, the popup may go off the screen.
arrow can be disabled or directed to the center via pointAtCenter. color accepts a preset or CSS color; custom background matches text color based on brightness. With your own semantic colors, check the contrast.
GetPopupContainer selects the popup location in the DOM after hydration. After changing the layout, wait for the tick and call ref.forceAlign(). The method concatenates calls and does not open a private tooltip. An open trigger is also tracked automatically.
Cache, Svelte snippets and design
By default, hidden scalar title is cached. fresh updates it and the semantic container when the popup is closed. The selected snippet can be saved, but its captured Svelte state remains reactive: there is no complete React.memo freezing.
destroyOnHidden removes content while preserving the native shell; forceRender creates hidden content and portal after hydration. These settings apply to the DOM, not to data retrieval or draft storage.
ConfigProvider.tooltip sets its class/style, semantic defaults, trigger, arrow and delays. classNames/styles are styled root/container/arrow; styles - CSS strings. Tooltip design tokens include maxWidth and zIndexPopup. Semantic styles root can override the explicit layer level.
Wrap adjacent buttons in Tooltip.UniqueProvider to move one tooltip between them. The shared popup changes content and position while keeping the same DOM element. Set unique={false} for a separate tooltip. Try the transition.
Your own Svelte component must output a real trigger; React.forwardRef is not needed here. Save its handlers, focus, and accessible name. Leave important information visible in the main page content so that it is not dependent on opening the tooltip.
A non-empty local prefixCls specifies the popup classes and the standard openClassName. The empty string and undefined inherit ConfigProvider.prefixCls with the -tooltip suffix, defaulting to ant-tooltip. Native wrapper, CSS variables and semantic slots preserve names. Example ConfigProvider shows inheritance, local exclusion and separate Tooltips inside Slider.
Examples
Quick tip
Hovering or focusing reveals additional description of the action.
<script lang="ts">
import { Button, Tooltip } from '@woodger/antd';
</script>
<Tooltip title={("Changes are saved automatically.")} trigger={['hover', 'focus']}>
<Button>{("How are changes saved?")}</Button>
</Tooltip>
Opening methods
Hover and focus, normal click and context menu.
<script lang="ts">
import { Button, Tooltip } from '@woodger/antd';
</script>
<style>
.examples {
display: flex;
flex-wrap: wrap;
gap: 12px;
}
</style>
<div class="examples">
<Tooltip title={("Opened by hover or focus")} trigger={['hover', 'focus']}>
<Button>{("Pointing and Focus")}</Button>
</Tooltip>
<Tooltip title={("Open by pressing")} trigger="click">
<Button>
{("Press")}
</Button>
</Tooltip>
<Tooltip title={("Open with right button")} trigger="contextMenu">
<Button>
{("Right button")}
</Button>
</Tooltip>
</div>
Twelve positions
Basic and angular positions around the trigger. There is a correction at the edge of the window.
<script lang="ts">
import { Button, Tooltip, type TooltipPlacement } from '@woodger/antd';
const positions = [
{ value: 'topLeft', label: 'TL', row: 1, column: 1 },
{ value: 'top', label: 'Top', row: 1, column: 2 },
{ value: 'topRight', label: 'TR', row: 1, column: 3 },
{ value: 'leftTop', label: 'LT', row: 2, column: 1 },
{ value: 'left', label: 'Left', row: 3, column: 1 },
{ value: 'leftBottom', label: 'LB', row: 4, column: 1 },
{ value: 'rightTop', label: 'RT', row: 2, column: 3 },
{ value: 'right', label: 'Right', row: 3, column: 3 },
{ value: 'rightBottom', label: 'RB', row: 4, column: 3 },
{ value: 'bottomLeft', label: 'BL', row: 5, column: 1 },
{ value: 'bottom', label: 'Bottom', row: 5, column: 2 },
{ value: 'bottomRight', label: 'BR', row: 5, column: 3 }
] as const satisfies readonly {
value: TooltipPlacement; label: string; row: number; column: number;
}[];
</script>
<style>
.positions {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 8px;
}
.cell {
display: flex;
justify-content: center;
}
.center {
grid-row: 2 / 5;
grid-column: 2;
display: grid;
place-items: center;
text-align: center;
color: var(--ant-color-text-secondary);
}
</style>
<div class="positions">
{#each positions as position (position.value)}
<div
class="cell"
style:grid-row={(position.row)}
style:grid-column={(position.column)}
>
<Tooltip title={("Position: " + String((position.value)) + "")} placement={position
.value} trigger={['hover', 'focus']}>
<Button aria-label={("Position " + String((position.value)) + "")}>{(position.label)}</Button>
</Tooltip>
</div>
{/each}
<div class="center">{("12 positions")}</div>
</div>
Arrow
A regular arrow, turning it off and directing it to the center of the button.
<script lang="ts">
import { Button, Tooltip } from '@woodger/antd';
</script>
<style>
.examples {
display: flex;
flex-wrap: wrap;
gap: 12px;
}
</style>
<div class="examples">
<Tooltip title={("Standard pointer")} placement="topLeft" trigger="click">
<Button>{("Regular hand")}</Button>
</Tooltip>
<Tooltip title={("Arrow hidden")} arrow={false} trigger="click">
<Button>{("Without arrow")}</Button>
</Tooltip>
<Tooltip title={("Arrow pointing to the center of the button")} placement="topLeft"
arrow={{ pointAtCenter: true }} trigger="click">
<Button>{("Center button")}</Button>
</Tooltip>
</div>
Automatic offset
Turn on the button at the bottom edge of the window and open the tooltip: it moves to the accessible area.
<script lang="ts">
import { Button, Checkbox, Tooltip } from '@woodger/antd';
let enabled = $state(false);
</script>
<style>
.edge {
position: fixed;
inset-inline-start: 12px;
bottom: 12px;
z-index: 20;
display: flex;
gap: 8px;
align-items: center;
}
</style>
<Checkbox bind:checked={enabled}>{("Show button at the edge of the screen")}</Checkbox>
{#if enabled}
<div class="edge">
<Tooltip title={("At the bottom edge, the tooltip is moved up and remains inside the window.")}
placement="bottom" trigger="click">
<Button type="primary">{("At the edge of the window")}</Button>
</Tooltip>
<Button
aria-label={("Remove the button at the edge")}
onclick={() => { enabled = false; }}
>×</Button>
</div>
{/if}
Changing layout and forceAlign
After changing the button's location, ref.forceAlign is called; an open prompt follows trigger.
<script lang="ts">
import { tick } from 'svelte';
import { Button, Tooltip, type TooltipRef } from '@woodger/antd';
let expanded = $state(false);
let open = $state(false);
let ref = $state<TooltipRef>();
async function changeLayout() {
expanded = !expanded;
await tick();
ref?.forceAlign();
}
</script>
<style>
.trigger { margin-top: 24px; }
.extra {
margin-top: 16px;
padding: 24px 12px;
background: var(--ant-color-fill-quaternary);
}
</style>
<Button onclick={changeLayout}>{("Change location")}</Button>
{#if expanded}<div class="extra">{("Additional block in front of the button.")}</div>{/if}
<div class="trigger">
<Tooltip
title={("Position updated after layout change")}
trigger={[]}
hideAction={[]}
placement="right"
bind:open
bind:ref
>
<Button onclick={() => { open = !open; }}>{("Binding to a button")}</Button>
</Tooltip>
</div>
Colors
Preset names and custom CSS background colors.
<script lang="ts">
import { Button, Tooltip } from '@woodger/antd';
const colors = ['magenta', 'green', 'purple', 'gold', '#2db7f5', '#f50'];
</script>
<style>
.examples {
display: flex;
flex-wrap: wrap;
gap: 12px;
}
</style>
<div class="examples">
{#each colors as color (color)}
<Tooltip title={("Color prompt: " + String((color)) + "")} {color} trigger={[
'hover',
'focus'
]}>
<Button>{(color)}</Button>
</Tooltip>
{/each}
</div>
Disable hint
An empty title removes the tooltip, leaving the button itself intact.
<script lang="ts">
import { Button, Checkbox, Tooltip } from '@woodger/antd';
let enabled = $state(true);
</script>
<style>
.examples {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 16px;
}
</style>
<div class="examples">
<Checkbox bind:checked={enabled}>{("Hint included")}</Checkbox>
<Tooltip title={(enabled ? "The tooltip is disabled by an empty title." : null)} trigger={[
'hover',
'focus'
]}>
<Button>{("Check hint")}</Button>
</Tooltip>
</div>
Presses: 0
Custom trigger
Svelte component with native button retains action, focus and tooltip binding.
CustomAction.svelte<script lang="ts"> import { Button } from '@woodger/antd'; let { onChoose }: { onChoose: () => void } = $props(); </script> <Button onclick={onChoose}>{("Custom Component")}</Button>Custom.svelte<script lang="ts"> import { Tooltip } from '@woodger/antd'; import CustomAction from './CustomAction.svelte'; let count = $state(0); </script> <Tooltip title={("Tooltip is bound to a native button inside the component")} trigger={[ 'hover', 'focus' ]}> <CustomAction onChoose={() => { count++; }} /> </Tooltip> <p role="status" aria-label={("Custom trigger action")}>{("Presses: ")}{count}</p>
Semantic DOM
The object and function classNames/styles are styled root, container and arrow.
<script lang="ts">
import { Button, Tooltip } from '@woodger/antd';
</script>
<style>
.examples {
display: flex;
flex-wrap: wrap;
gap: 12px;
}
</style>
<div class="examples">
<Tooltip
title={("Semantic styles object")}
trigger="click"
classNames={{ root: 'tooltip-semantic-object' }}
styles={{
container: `
padding: 16px;
border-radius: 12px;
font-weight: 600;
`,
arrow: 'opacity:0.65'
}}
>
<Button>{("Styles by object")}</Button>
</Tooltip>
<Tooltip title={("Function semantic styles")} trigger="click" placement="top"
classNames={() => ({ root: 'tooltip-semantic-function' })}
styles={({ props }) => ({
container: props.placement === 'top'
? 'font-weight:700'
: 'font-weight:400'
})}>
<Button>{("Styles function")}</Button>
</Tooltip>
</div>
Open: no
Cache and content deletion
Managed open, scalar title, fresh and destroyOnHidden.
<script lang="ts">
import { Button, Checkbox, Input, Tooltip } from '@woodger/antd';
let title = $state<string | undefined>(("First label"));
let fresh = $state(false);
let destroy = $state(false);
let open = $state(false);
</script>
<style>
.controls {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 12px;
margin-bottom: 20px;
}
.field { width: 200px; }
</style>
<div class="controls">
<div
class="field"
><Input
aria-label={("Cacheable hint text")}
bind:value={title}
/></div>
<Checkbox bind:checked={fresh}>fresh</Checkbox>
<Checkbox bind:checked={destroy}>destroyOnHidden</Checkbox>
</div>
<Tooltip id="tooltip-cache-preview" title={(title ?? '')} {fresh} destroyOnHidden={destroy}
trigger="click" bind:open>
<Button>{("Cacheable hint")}</Button>
</Tooltip>
<p role="status" aria-label={("Cacheable tooltip visibility")}>{("Open: ")}{(open ? "yes" : "no")}</p>
General settings
ConfigProvider.tooltip specifies trigger, delay and arrow; local prop specifies the setting.
<script lang="ts">
import { Button, ConfigProvider, Tooltip } from '@woodger/antd';
</script>
<style>
.examples {
display: flex;
flex-wrap: wrap;
gap: 12px;
}
</style>
<ConfigProvider tooltip={({
trigger: ['hover', 'focus'],
arrow: false,
mouseEnterDelay: 0
})}>
<div class="examples">
<Tooltip title={("Settings inherited from ConfigProvider")}>
<Button>
{("General settings")}
</Button>
</Tooltip>
<Tooltip title={("Local arrow has priority")} arrow>
<Button>
{("Local arrow")}
</Button>
</Tooltip>
</div>
</ConfigProvider>
Component tokens
Local theme changes maxWidth and zIndexPopup.
<script lang="ts">
import { Button, ConfigProvider, Tooltip } from '@woodger/antd';
</script>
<ConfigProvider theme={{ components: { Tooltip: { maxWidth: 180, zIndexPopup: 1120 } } }}>
<Tooltip title={("The long label wraps within the specified maximum tooltip width.")}
trigger={['hover', 'focus']}>
<Button>{("Tooltip Tokens")}</Button>
</Tooltip>
</ConfigProvider>
Popup container
getPopupContainer selects the popup location in the DOM after hydration.
<script lang="ts">
import { Button, Tooltip } from '@woodger/antd';
let container = $state<HTMLDivElement>();
</script>
<style>
.container {
padding: 20px;
border: 1px dashed var(--ant-color-border);
border-radius: 8px;
}
</style>
<div class="container" bind:this={container}>
<Tooltip title={("Popup is located inside the selected container")} trigger="click"
getPopupContainer={trigger => container ?? trigger.ownerDocument.body}>
<Button>{("Open in container")}</Button>
</Tooltip>
</div>
Escape closes the tooltip and maintains focus. At the edge of the window, the position changes automatically.
Tips from the review
Saved example with position settings, arrow and external controls.
<script lang="ts">
import { Button, Checkbox, Tooltip, type TooltipPlacement } from '@woodger/antd';
let placement = $state<TooltipPlacement>('top');
let arrow = $state(true);
let open = $state(false);
</script>
<style>
.settings, .examples {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 12px;
}
.settings { margin-bottom: 28px; }
.settings label {
display: flex;
align-items: center;
gap: 8px;
}
select {
padding: 4px 8px;
color: var(--ant-color-text);
background: var(--ant-color-bg-container);
border: 1px solid var(--ant-color-border);
border-radius: 6px;
font: inherit;
}
.note {
margin: 20px 0 0;
color: var(--ant-color-text-secondary);
}
</style>
<div class="settings">
<label>{("Prompt position ")}<select
bind:value={placement}
><option
value="top"
>{("Top")}</option><option
value="bottom"
>{("Bottom")}</option><option
value="left"
>{("Left")}</option><option
value="right"
>{("Right")}</option></select></label>
<Checkbox bind:checked={arrow}>{("Arrow")}</Checkbox>
</div>
<div class="examples">
<Tooltip
title={("Changes will be saved after the form is validated.")}
{placement}
{arrow}
><Button>{("Hover or Tab")}</Button></Tooltip>
<Tooltip
title={("Available after filling out the form.")}
{placement}
{arrow}
><Button
disabled
>{("Unavailable action")}</Button></Tooltip>
<Tooltip
title={("The tooltip can be controlled via bind:open.")}
bind:open
{placement}
{arrow}
trigger={[]}
><Button
onclick={() => { open = !open; }}
>{("Show hint")}</Button></Tooltip>
</div>
<p class="note">{("Escape closes the tooltip and maintains focus. At the edge of the window, the position changes automatically.")}</p>
API
Tooltip.UniqueProvider lets adjacent tooltips share a single popup.
| Theme | Example or limitation |
|---|---|
| Basic | Hover and focus tooltip. |
| Smooth Transition | Uses the shared surface of the nearest Tooltip.UniqueProvider. |
| Placement | All 12 physical directions. |
| Arrow | true, false and pointAtCenter. |
| Auto Shift | Real viewport edge, translation and offset. |
| Realign after layout changes | bind:ref and forceAlign after tick. |
| Colorful Tooltip | Preset and CSS colors. |
| Disabled | An empty title disables the tooltip. |
| Wrap custom component | DOM trigger inside its own Svelte component. |
| Custom semantic dom styling | styles/classNames object and function. |
| Property | Description | Type | Default |
|---|---|---|---|
unique | Uses the shared surface of the nearest Tooltip.UniqueProvider. | boolean | Tooltip.UniqueProvider |
motion | CSS transition name. An empty string disables animation. | { motionName?: string } | zoom-big-fast |
afterOpenChange | Runs after a standalone popup finishes its transition. | (open: boolean) => void | — |
prefixCls | Full local CSS prefix of popup and standard openClassName; native wrapper and CSS variables are preserved. The empty string and undefined inherit ConfigProvider.prefixCls; default ant-tooltip. | string | ConfigProvider + -tooltip |
hideAction | Closing events. [] disables trigger/outside closure, preserving Escape. | readonly TooltipTrigger[] | trigger |
title | Text, number, content array or Snippet. Empty content hides the tooltip. | TooltipContent | — |
placement | Four main and eight corner directions; left/right physical also in RTL. | TooltipPlacement | top |
alignPoint | Anchors the popup to the pointer coordinates. | boolean | false |
trigger | hover, focus, click, contextMenu; [] leaves external control. | TooltipTrigger | readonly TooltipTrigger[] | native hover/focus/context |
open | Supports bind:open; the owner of the managed value accepts the changes. | boolean | undefined | local state |
defaultOpen | Initial local state. | boolean | false |
onOpenChange | Notification of visibility changes. | (open: boolean) => void | — |
arrow | Visibility of the arrow and direction to the center. | boolean | { pointAtCenter?: boolean } | true |
color | Preset or CSS background color; for custom color, the text is selected based on brightness. | TooltipColor | theme |
autoAdjustOverflow | Position correction. adjustX/adjustY accept 0 or 1. | boolean | AdjustOverflow | true |
align | Additional alignment and offset options. | TooltipAlignConfig | — |
mouseEnterDelay | Hover opening delay in seconds. | number | 0.1 |
mouseLeaveDelay | Hover-closing delay in seconds. | number | 0.1 |
getPopupContainer | Browser-only container selection. The local function takes precedence over ConfigProvider. | (trigger: HTMLElement) => HTMLElement | native inline / context |
fresh | Updates the payload of a private tip; opaque Snippet retains its own reactivity. | boolean | false |
destroyOnHidden | Removes contents when closed, preserving the native shell. | boolean | false |
forceRender | Mounts hidden content and portal after hydration. | boolean | false |
disabled | Hides popup, keeping trigger and raw open. | boolean | false |
id | Tooltip ID for ARIA communication with trigger. | string | stable ID |
zIndex | Explicit CSS z-index before semantic root styles. | number | theme |
classNames | Classes root/container/arrow; object or function. | TooltipSemantic | — |
styles | CSS lines root/container/arrow; object or function. | TooltipSemantic | — |
ConfigProvider and ref
tooltip sets general trigger, arrow, delays, class/style and semantic styles. Local props refine the settings. To open from the keyboard, explicitly enable focus. A nested provider replaces the entire tooltip object; undefined inherits from the parent.
bind:ref returns TooltipRef after mount. nativeElement points to the DOM trigger, including SVG; popupElement - on native span shell. forceAlign updates the alignment without opening the closed tooltip. Binding is cleared upon unmount.
Semantic DOM
Svelte implementation links trigger and surface with role=tooltip via aria-describedby. Popup uses native popover and top layer; by default its shell remains next to trigger. getPopupContainer can transfer it to the selected DOM container after hydration.
| Slot | Purpose |
|---|---|
root | popup surface, position, layer and maximum width. |
container | Text, background, padding, radius and shadow. |
arrow | Hint arrow. |
classNames and styles accept an object or function with props; styles are set by CSS strings. The content of the tooltip describes the trigger. Place interactive elements in Popover.
Registration tokens
Set zIndex for an explicit layer. A nested tooltip takes its dialog’s layer into account.
| Token | Purpose |
|---|---|
maxWidth | Maximum tooltip width. |
zIndexPopup | CSS tooltip layer. |
| Token | Meaning |
|---|---|
colorBgSpotlight | rgba(0,0,0,0.85) |
colorTextLightSolid | #fff |
fontSize | 14 |
lineHeight | 1.5714285714285714 |
paddingXS | 8 |
paddingSM | 12 |
sizePopupArrow | 16 |
motionDurationMid | 0.2s |
FAQ
Why has the situation changed?
autoAdjustOverflow adjusts the position at the edge of the viewport. The main sides allow flip/shift, the corner sides allow flip.
Why is the closed title not updated?
Scalar payload is cached before opening. fresh updates it immediately; reactivity inside the snippet is not frozen.
When is forceAlign needed?
After changing the layout, you can call it via ref after tick. This method does not open a closed popup.
How to use a custom component?
It should output the real DOM trigger. Save its name, keyboard and custom action.