Skip to content

Tooltip

Hover tooltips via Svelte 5 attachments. Automatically integrated with Button’s title prop.

import { tooltip } from "phoundry-ui";

Button with Title

Loading interactive example…

View source
button-with-title.svelte
<script lang="ts">
import { Button } from "phoundry-ui";
import { PhiIcons } from "phoundry-ui";
</script>
<div class="flex items-center gap-3">
<Button title="Save your work" icon={PhiIcons.check} />
<Button title="Edit item" icon={PhiIcons.edit} />
<Button title="Search" icon={PhiIcons.search} />
</div>

Tooltip Attachment

Loading interactive example…

View source
tooltip-attachment.svelte
<script lang="ts">
import { tooltip } from "phoundry-ui";
</script>
<div class="flex flex-wrap items-center gap-4">
<span
{@attach tooltip("This is a tooltip")}
class="cursor-default rounded border border-border-muted px-3 py-1.5 text-sm text-txt-secondary"
>
String shorthand
</span>
<span
{@attach tooltip({ content: "Uses TooltipOptions shape", disabled: false })}
class="cursor-default rounded border border-border-muted px-3 py-1.5 text-sm text-txt-secondary"
>
Options object
</span>
</div>

Snippet content

Loading interactive example…

View source
snippet-content.svelte
<script lang="ts">
import { tooltip } from "phoundry-ui";
</script>
<div>
{#snippet richTooltip()}
<span class="text-xs"
>Rich <strong class="text-txt-primary">snippet</strong> body</span
>
{/snippet}
<span
{@attach tooltip({ content: richTooltip })}
class="cursor-default rounded border border-border-muted px-3 py-1.5 text-sm text-txt-secondary"
>
Hover for snippet
</span>
</div>

tooltip() attachment

From phoundry-ui@0.4.21

NameTypeDefaultDescription
contentrequiredTooltipContent—Tooltip body - plain text or a snippet with richer markup.
disabledboolean | undefined—Skip attaching listeners - useful while loading.

tooltip(…): Pass a string for shorthand (tooltip("Hi") expands to { content: "Hi" }). Otherwise use { content, disabled? }.

Usage tips

  • Initialize overlays once via setupOverlays() (or wire providers manually) and mount TooltipOverlay beside other overlays - the attachment talks to getTooltipManager().
  • Button with a title prop automatically uses the tooltip system. Set noTooltip to use the native browser title instead.
  • Tooltips hide on pointer leave, immediately on click, and on window scroll (capture phase).
  • Prefer concise strings in tooltips; move long help text into dialogs or docs - hover delays make long copy hard to read.

Tooltips respond to hover-capable pointer entry. Touch entry does not open a tooltip, and a pointer press hides any visible tooltip immediately.

CSS styling

.ph-tooltip is the stable identification hook for Tooltip. Part selectors and --_ph-* properties are internal. Component CSS is scoped and unlayered; Consumer classes remain additive and utility overrides may lose precedence.

Tooltip chrome and entry animation are local to the overlay. Position measurements and content behavior are unchanged.

Keep the shared component stylesheet and a named Theme imported. Decorative motion respects reduced-motion preferences.

Documentation is licensed under CC BY 4.0. Phoundry names and marks remain reserved.