Tooltip
Installation
npx @mielui/svelte add tooltipyarn dlx @mielui/svelte add tooltipbunx @mielui/svelte add tooltipUsage
Wrap a focusable control in Trigger and put its hint in Content. The hint opens when the pointer rests or the keyboard focuses, and Escape closes it. Root and Provider add no element, and Trigger wraps its child in an inline span.
<script lang="ts">
import { Button } from '@mielui/svelte/components/button';
import * as Tooltip from '@mielui/svelte/components/tooltip';
</script>
<Tooltip.Root>
<Tooltip.Trigger>
<Button variant="outline">Info</Button>
</Tooltip.Trigger>
<Tooltip.Content>Helpful text here</Tooltip.Content>
</Tooltip.Root>placement on Root picks the side, top by default, and the bubble flips when it would leave the viewport. delay and closeDelay are in milliseconds, 500 and 100 by default. delay is how long the pointer rests on the trigger: keyboard focus opens the tooltip at once, while a click that focuses the trigger still waits. Moving to another trigger while a tooltip is open skips the delay. Set showOnClick on Trigger to also show the tooltip on click, for touch screens or to confirm a copy.
Examples
Toolbar shortcuts
Each icon button names its tool and shows the keyboard shortcut beside it.
Top placement
Right placement
Bottom placement
Rich content and Provider
Content shows plain text by default. Set rich to keep formatting and SVG icons. The bubble is a passive copy without ids, event handlers, or form controls, so use Popover for links and buttons. All tooltips share one moving bubble; wrap a region in Tooltip.Provider to give it its own bubble.
Glass surface
surface="glass" on Content gives the bubble a translucent, blurred background. Leave surface out to follow the theme, or set surface="solid" to override it. Glass falls back to an opaque surface when backdrop filters are unavailable or reduced transparency is on.
API reference
Tooltip.Root
Controls tooltip state.
delaynumberMilliseconds the pointer rests on the trigger before the tooltip opens. Keyboard focus opens it at once, and a neighbour opens at once while one is showing.
Default
500closeDelaynumberMilliseconds after the pointer leaves before it closes.
Default
100placementTooltipPlacementSide of the trigger the tooltip opens on.
Default
'top'childrenSnippet<[]>Content rendered inside.
Tooltip.Content
Renders tooltip content.
classstringClasses added to the element.
childrenSnippet<[]>Content rendered inside.
surface"solid" | "glass"Surface treatment. Omit it to inherit
--mielui-surfacefrom the theme.richbooleanShows the content's markup in the bubble instead of its plain text.
Default
false
Tooltip.Provider
childrenSnippet<[]>Content rendered inside.
Tooltip.Trigger
Opens the tooltip.
showOnClickbooleanAlso shows the tooltip when the trigger is clicked, for touch screens.
Default
falseclassstringClasses added to the element.
childrenSnippet<[]>Content rendered inside.
pnpm dlx @mielui/svelte add tooltip