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
| Name | Type | Default | Description |
|---|---|---|---|
content | string | Snippet | Component | 'I am a tooltip' | The content to display in the tooltip. |
class | string | The class to apply to the tooltip. | |
ref bindable | HTMLElement | The DOM reference of the tooltip element. | |
target | HTMLElement | The element the tooltip is anchored to. Falls back to the rendered children. | |
open bindable | boolean | false | Controls the open state of the tooltip. |
withArrow | boolean | false | Whether the tooltip has an arrow pointing at its target. |
positionConfig | ComputePositionConfig | The position configuration handed over to floating-ui. | |
openDelay | number | 100 | The delay in milliseconds before the tooltip is shown. |
hideDelay | number | 300 | The delay in milliseconds before the tooltip is hidden. |
onVisibleChange | (visible: boolean) => void | Callback 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. |
placement | Placement | Where the tooltip is placed relative to its target. | |
id | string | The id of the tooltip element, referenced by the target. Falls back to a generated id. | |
preventClose bindable | boolean | false | Keeps the tooltip open until it is closed by hand. |
animationFrame | boolean | false | Repositions the tooltip on every animation frame, for a target that keeps moving. |
children | Snippet | The target of the tooltip. It receives the ARIA attributes and the attachment to spread on your element. | |
HTMLAttributes<HTMLDivElement> without children |
