Skip to content

Meta: turn tooltipped into svelte component#9844

Merged
fregante merged 11 commits into
mainfrom
fregante-patch-1
Jul 17, 2026
Merged

Meta: turn tooltipped into svelte component#9844
fregante merged 11 commits into
mainfrom
fregante-patch-1

Conversation

@fregante

@fregante fregante commented Jul 16, 2026

Copy link
Copy Markdown
Member

Plan

  • have the DOM in the svelte component, usable from both JSX and Svelte
  • use portals so that the tooltip is automatically rendered elsewhere on the document, if that works

@github-actions github-actions Bot added the meta Related to Refined GitHub itself label Jul 16, 2026
fregante added 7 commits July 17, 2026 02:52
Refactor createTooltipFor to not return a container and update tooltipped function to directly create tooltips.
@fregante
fregante marked this pull request as ready for review July 17, 2026 10:25
Comment on lines 13 to 17
// Ensure the element has an ID for the `for` attribute to link to
element.id ||= crypto.randomUUID();

const tooltipId = crypto.randomUUID();
element.setAttribute('aria-labelledby', tooltipId);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't yet figured out a way to simplify tooltip usage in svelte components. It's possible but this logic is not sveltified yet.

Options include:

  • using a svelte action, but that actually is unable to cleanly mount components to the element that calls the action. It can however call its own mount elsewhere (😖)
  • creating an additional wrapper like <Wrapper label="click me"><button/></Wrapper> that includes this logic, but it's a bit dirty via onMount and direct DOM access to get/set the id like createTooltipFor is doing

Comment on lines -80 to +38
const tooltip = createTooltipFor(element, content);
element.append(tooltip);

queueMicrotask(() => {
// TODO: Replace with https://github.com/sindresorhus/ts-extras/issues/75
if (!element.isConnected) {
throw new Error('Element must be attached to the document before the tooltip');
}

attachToDocument(tooltip);
});

createTooltipFor(element, content);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Svelte is cool in that it can wrap this functionality in any <Tooltip> mount via portals.

</a>
{#if tab.tooltip}
<Tooltip id="{id}-tooltip" htmlFor={id} label={tab.tooltip} />
{/if}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done:

Image

It lacks the automatic ID creation but the code is quite reasonable.

@fregante
fregante merged commit 12a1745 into main Jul 17, 2026
13 checks passed
@fregante
fregante deleted the fregante-patch-1 branch July 17, 2026 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

meta Related to Refined GitHub itself

Development

Successfully merging this pull request may close these issues.

1 participant