Skip to content

fix(web): support changing tooltip text programmatically#4562

Merged
mimarz merged 25 commits intomainfrom
programmatic-tooltip
Mar 13, 2026
Merged

fix(web): support changing tooltip text programmatically#4562
mimarz merged 25 commits intomainfrom
programmatic-tooltip

Conversation

@stianmorsund
Copy link
Copy Markdown
Collaborator

@stianmorsund stianmorsund commented Mar 3, 2026

Summary

Support changing tooltip programmatically by updating text of the existing tooltip and announcing change to screen readers. Also made a global announcer and refactored field to use it.

Checks

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 3, 2026

🦋 Changeset detected

Latest commit: 6244c84

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@digdir/designsystemet-web Patch
@digdir/designsystemet-react Patch
@digdir/designsystemet Patch
@digdir/designsystemet-css Patch
@digdir/designsystemet-types Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@stianmorsund stianmorsund changed the title feat(web): support changing tooltip text programatically feat(web): support changing tooltip text programmatically Mar 3, 2026
@stianmorsund stianmorsund changed the title feat(web): support changing tooltip text programmatically fix(web): support changing tooltip text programmatically Mar 3, 2026
@stianmorsund stianmorsund force-pushed the programmatic-tooltip branch from 1bf3f89 to 6348ad7 Compare March 3, 2026 11:15
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 3, 2026

Preview deployments for this pull request:

storybook - 10. Mar 2026 - 10:34

www - 3. Mar 2026 - 13:38

Copy link
Copy Markdown
Member

@Barsnes Barsnes left a comment

Choose a reason for hiding this comment

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

Can you add a storybook story for this? Would be great to test it out

@stianmorsund
Copy link
Copy Markdown
Collaborator Author

Can you add a storybook story for this? Would be great to test it out

Sure!

@oddvernes
Copy link
Copy Markdown
Collaborator

Hmm I see the text change only after moving the mouse away (so the tooltip goes away) and then back
Apple voiceover does not seem to react to pressing the button. (Don't know if being inside an iframe may affect this)

@eirikbacker
Copy link
Copy Markdown
Contributor

eirikbacker commented Mar 3, 2026

Hmm I see the text change only after moving the mouse away (so the tooltip goes away) and then back Apple voiceover does not seem to react to pressing the button. (Don't know if being inside an iframe may affect this)

iframe has issues with aria-live in Mac yeah :( works now in VoiceOver 🤗

I made some minor tweaks to make it CSP friendly and to clear the aria-live-area after announcement so screen readers can not find it by accident ☺️ Also, the LIVE-element might be removed by frameworks, so I'll let the mount-function run the entire lifetime :)

Overall; great work @stianmorsund 💯 👏 💪

Comment thread packages/web/src/tooltip/tooltip.ts
Comment thread packages/web/src/tooltip/tooltip.ts
Comment thread packages/web/src/utils/utils.ts
Comment thread packages/web/src/utils/utils.ts
Comment thread packages/web/src/utils/utils.ts
@stianmorsund
Copy link
Copy Markdown
Collaborator Author

Hmm I see the text change only after moving the mouse away (so the tooltip goes away) and then back Apple voiceover does not seem to react to pressing the button. (Don't know if being inside an iframe may affect this)

iframe has issues with aria-live in Mac yeah :( works now in VoiceOver 🤗

I made some minor tweaks to make it CSP friendly and to clear the aria-live-area after announcement so screen readers can not find it by accident ☺️ Also, the LIVE-element might be removed by frameworks, so I'll let the mount-function run the entire lifetime :)

Overall; great work @stianmorsund 💯 👏 💪

Awesome, thanks for the review 💯 👍

@stianmorsund
Copy link
Copy Markdown
Collaborator Author

Hmm I see the text change only after moving the mouse away (so the tooltip goes away) and then back Apple voiceover does not seem to react to pressing the button. (Don't know if being inside an iframe may affect this)

Thanks for testing! ☺️ Hmm, I couldn't reproduce that. I guess you tested in Storybook since you mentioned iframe?

@eirikbacker
Copy link
Copy Markdown
Contributor

Hmm I see the text change only after moving the mouse away (so the tooltip goes away) and then back Apple voiceover does not seem to react to pressing the button. (Don't know if being inside an iframe may affect this)

Thanks for testing! ☺️ Hmm, I couldn't reproduce that. I guess you tested in Storybook since you mentioned iframe?

Iframes is in general flaky in regards of reading aria-live, same with ShadowDOM ☺️ Therefore; I did testing for this in with Storybooks isolation mode - with success ☺️

@Barsnes
Copy link
Copy Markdown
Member

Barsnes commented Mar 4, 2026

Hmm I see the text change only after moving the mouse away (so the tooltip goes away) and then back Apple voiceover does not seem to react to pressing the button. (Don't know if being inside an iframe may affect this)

Thanks for testing! ☺️ Hmm, I couldn't reproduce that. I guess you tested in Storybook since you mentioned iframe?

Iframes is in general flaky in regards of reading aria-live, same with ShadowDOM ☺️ Therefore; I did testing for this in with Storybooks isolation mode - with success ☺️

it works fine on windows + chrome + nvda :)

@mimarz
Copy link
Copy Markdown
Collaborator

mimarz commented Mar 6, 2026

Anyone looking at failing test? 😅 @stianmorsund

Copy link
Copy Markdown
Collaborator

@mimarz mimarz left a comment

Choose a reason for hiding this comment

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

This looks ok for me but @Barsnes or @eirikbacker should also take a final look as they know this part of the codebase the best :)

Copy link
Copy Markdown
Member

@Barsnes Barsnes left a comment

Choose a reason for hiding this comment

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

Eirik is away on vacation, but this looks good to me. Works fine for me on windows + nvda as well :)

@mimarz mimarz merged commit 5776e4b into main Mar 13, 2026
16 of 17 checks passed
@mimarz mimarz deleted the programmatic-tooltip branch March 13, 2026 08:45
@github-actions github-actions Bot mentioned this pull request Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants