enes

Tooltip

A tooltip displays additional information about another component. The information is displayed above and near the target component.

Usage

Use a children snippet to receive the tooltip's accessibility attributes and spread them onto the target element. The snippet also receives an attachment as its second argument, which you can attach to the element that should act as the trigger.

<script>
	import { Tooltip, Button } from 'fluentui-svelte';
</script>

<Tooltip content="Tooltip content" relationship="description" withArrow>
	{#snippet children(attrs)}
		<Button {...attrs}>Hover over me</Button>
	{/snippet}
</Tooltip>

You can also pass the target directly as a child. The tooltip then attaches itself to the next rendered element, but the accessibility attributes are not applied.

<script>
	import { Tooltip, Button } from 'fluentui-svelte';
</script>

<Tooltip content="Tooltip content" relationship="description" withArrow>
  <Button>Hover over me</Button>
</Tooltip>

Component API

A brief explanation of the props that really need explaining. You can see the rest of the props in the Component Props section below.

With Arrow

The withArrow prop is a boolean that, when set to true, adds an arrow to the tooltip pointing towards the target element. This can help visually connect the tooltip to the element it is describing.

Delay

The openDelay and hideDelay props allow you to specify a delay, in milliseconds, before the tooltip is shown or hidden after the user hovers over the target element. This can help prevent the tooltip from appearing or disappearing too quickly.

Component Props

NameTypeDefaultDescription
contentstring | Snippet | Component'I am a tooltip'The content to display in the tooltip.
classstringThe class to apply to the tooltip.
ref bindableHTMLElementThe DOM reference of the tooltip element.
targetHTMLElementThe element the tooltip is anchored to. Falls back to the rendered children.
open bindablebooleanfalseControls the open state of the tooltip.
withArrowbooleanfalseWhether the tooltip has an arrow pointing at its target.
positionConfigComputePositionConfigThe position configuration handed over to floating-ui.
openDelaynumber100The delay in milliseconds before the tooltip is shown.
hideDelaynumber300The delay in milliseconds before the tooltip is hidden.
onVisibleChange(visible: boolean) => voidCallback function that is called when the visibility of the tooltip changes.
relationship'label' | 'description' | 'inaccessible''label'The relationship of the tooltip to its target, which decides how it is announced.
placementPlacementWhere the tooltip is placed relative to its target.
idstringThe id of the tooltip element, referenced by the target. Falls back to a generated id.
preventClose bindablebooleanfalseKeeps the tooltip open until it is closed by hand.
animationFramebooleanfalseRepositions the tooltip on every animation frame, for a target that keeps moving.
childrenSnippetThe target of the tooltip. It receives the ARIA attributes and the attachment to spread on your element.
HTMLAttributes<HTMLDivElement> without children