Skip to content
iv-ui v0.3.0

Tooltip

since 0.2.0

A short label shown on hover or focus.

import { Tooltip } from '@elluzion/iv-ui';

Positions

The preferred side flips automatically when space runs out.

Source· svelte Show Hide
<script lang="ts">
	import { Button, Tooltip } from '@elluzion/iv-ui';
</script>

<div class="row">
	{#each ['top', 'bottom', 'left', 'right'] as side (side)}
		<Tooltip label="{side} tooltip" position={side as 'top' | 'bottom' | 'left' | 'right'}>
			<Button variant="outline" size="sm">{side}</Button>
		</Tooltip>
	{/each}
</div>

<style>
	.row {
		display: flex;
		flex-wrap: wrap;
		justify-content: center;
		gap: var(--iv_spacing-sm);
	}
</style>
  • Wrap the trigger; label is the tooltip text and the child stays the trigger.
  • delay defaults to 300 ms; Escape hides an open tooltip.
  • Tooltips supplement a visible label; they never replace one.

Delay

A short delay for dense toolbars, a longer one for prose.

Source· svelte Show Hide
<script lang="ts">
	import { Button, Tooltip } from '@elluzion/iv-ui';
</script>

<div class="row">
	<Tooltip label="Opens immediately" delay={0}>
		<Button variant="outline" size="sm">No delay</Button>
	</Tooltip>
	<Tooltip label="Opens after 700 ms" delay={700}>
		<Button variant="outline" size="sm">Long delay</Button>
	</Tooltip>
</div>

<style>
	.row {
		display: flex;
		flex-wrap: wrap;
		justify-content: center;
		gap: var(--iv_spacing-sm);
	}
</style>

Custom content

The content snippet can hold a shortcut, a hint, or both.

Source· svelte Show Hide
<script lang="ts">
	import { Button, Shortcut, Tooltip } from '@elluzion/iv-ui';
</script>

<Tooltip position="bottom">
	{#snippet content()}
		<span class="content">Command palette <Shortcut keys={['⌘', 'K']} /></span>
	{/snippet}
	<Button variant="outline" size="sm">Open palette</Button>
</Tooltip>

<style>
	.content {
		display: inline-flex;
		align-items: center;
		gap: var(--iv_spacing-sm);
	}
</style>
import { Tooltip } from '@elluzion/iv-ui';

Props

5 props · 0 events · 2 snippets
PropTypeDefaultDescription
label string''Tooltip text.
position TooltipPosition'top'Preferred side of the trigger.
delay number300Delay before showing, in milliseconds.
disabled booleanfalseDisables interaction and applies the disabled treatment.
className string''Extra classes merged onto the root element.

Snippets

SnippetTypeDescription
contentSnippetCustom tooltip content replacing the label.
childrenSnippetThe trigger element.

Types

TooltipPosition

Side of the trigger the tooltip prefers.

type TooltipPosition = 'top' | 'bottom' | 'left' | 'right';
KeysAction
EscapeHides an open tooltip.
  • The wrapper points at the tooltip with aria-describedby only while it is visible.
  • Focus and hover both open the tooltip; leaving or blurring closes it.
  • Touch devices do not show hover tooltips, so keep the information available in the interface.
Class hooks
.iv-ready.iv-root.iv-tooltip
iv-ui
↑ ↓ navigate ↵ open esc close minisearch · 482 records