resolver
Description
Optional. A function called on every hovered element that returns the tooltip contentUsage
resolver?: (element: HTMLElement, event: MouseEvent) => string | object | null;
Parameters
The resolver function receives two arguments:
element- a DOM ancestor ofevent.target, passed to the resolver in order from innermost to outermostevent- theMouseEventthat triggered the hover
It is called for each ancestor element in turn; the first non-null return wins and that element becomes the tooltip positioning anchor.
Return value:
string— displayed as plain text when nocontentis set; passed as<Content data={string} />whencontentis setobject— spread as props intocontent(<Content {...result} />); when nocontentis set,result.datais rendered as textnull— check continues to the next ancestor; if all ancestors returnnull, no tooltip is shown
The default resolver reads the data-tooltip-text attribute of each checked element.
Example
<Tooltip
content={UserCard}
resolver={el => el.dataset.userId ? { id: Number(el.dataset.userId) } : null}
>
{#each users as user}
<div data-user-id={user.id}>{user.label}</div>
{/each}
</Tooltip>
Related article: Render custom content in a tooltip
Related sample: Tooltip