Meta: turn tooltipped into svelte component#9844
Merged
Merged
Conversation
fregante
marked this pull request as ready for review
July 17, 2026 10:25
fregante
commented
Jul 17, 2026
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); |
Member
Author
There was a problem hiding this comment.
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
mountelsewhere (😖) - 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 theidlikecreateTooltipForis 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); |
Member
Author
There was a problem hiding this comment.
Svelte is cool in that it can wrap this functionality in any <Tooltip> mount via portals.
fregante
commented
Jul 17, 2026
| </a> | ||
| {#if tab.tooltip} | ||
| <Tooltip id="{id}-tooltip" htmlFor={id} label={tab.tooltip} /> | ||
| {/if} |
Member
Author
This was referenced Jul 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

extensible-nav- Allow extension by other features #9832Plan