Skip to content

fix(Tooltip): only set aria-label if there is no accessible text, and deprecate type prop#4898

Open
unekinn wants to merge 7 commits into
mainfrom
fix/tooltip-react-label-vs-description
Open

fix(Tooltip): only set aria-label if there is no accessible text, and deprecate type prop#4898
unekinn wants to merge 7 commits into
mainfrom
fix/tooltip-react-label-vs-description

Conversation

@unekinn
Copy link
Copy Markdown
Contributor

@unekinn unekinn commented May 18, 2026

Summary

  1. Tooltip: deprecate type prop, as it no longer does anything (since v1.12.0 rewrite to use designsystemet-web)
  2. Tooltip: the React component will no longer override existing accessible text. It now correctly sets aria-description in that case. If there is no accessible text, aria-label will be used as before.

NOTE: The complicated hasAccessibleText() function is only necessary if we want to keep aria-label/aria-description server rendered (except in case of React Suspense, in which case it will be deferred to the custom element). Writing it was a nice learning experience, but it is a lot more complicated than the same logic which exists in the custom element client side, and I'm not sure it's worth the hassle?
EDIT: This is removed, and now only done on the client

Checks

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 18, 2026

🦋 Changeset detected

Latest commit: 7fcb60a

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-react Patch
@digdir/designsystemet Patch
@digdir/designsystemet-css Patch
@digdir/designsystemet-types Patch
@digdir/designsystemet-web 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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 18, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 36451d20-eee7-44c3-8695-ea77dc16fe4a

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/tooltip-react-label-vs-description

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 18, 2026

Preview deployments for this pull request:

storybook - 20. May 2026 - 14:14

@eirikbacker
Copy link
Copy Markdown
Contributor

eirikbacker commented May 19, 2026

Oh, nice work! ⭐ Though, I must say I agree a bit with you - my immediate feeling is that we should not rely on Reacts inner workings, ship extra JS or extend "framework components" (I hope we'll be able to add more than React soon), so I'd prefer client-side-logic for this one ☺️ any thoughts @mimarz? ☺️

@mimarz
Copy link
Copy Markdown
Collaborator

mimarz commented May 19, 2026

Maybe we could add a play function to open the tooltips for chromatic visual tests?

NOTE: The complicated hasAccessibleText() function is only necessary if we want to keep aria-label/aria-description server rendered (except in case of React Suspense, in which case it will be deferred to the custom element). Writing it was a nice learning experience, but it is a lot more complicated than the same logic which exists in the custom element client side, and I'm not sure it's worth the hassle?

Lets maybe try without first? It does look complicated and cumbersome to maintain. We can revaluate if it becomes a problem for users downstream.

We want the React components to be as simple as possible to ensure wide compability and behaviour across all web framework/libraries.

@unekinn
Copy link
Copy Markdown
Contributor Author

unekinn commented May 19, 2026

Maybe we could add a play function to open the tooltips for chromatic visual tests?

Good idea, I will do that.

Lets maybe try without first? It does look complicated and cumbersome to maintain. We can revaluate if it becomes a problem for users downstream.

Agreed, I only added this because of the following comment in the original code:

// designsystemet-web will re-evaulate if this should be an aria-label or aria-description, but kept here for better SSR

However, we have a lot of other components where the aria-* doesn't get SSR'ed so it doesn't make much sense to go to great lengths to SSR it here.

@unekinn unekinn force-pushed the fix/tooltip-react-label-vs-description branch from 77c115a to da9a08d Compare May 19, 2026 13:25
@unekinn
Copy link
Copy Markdown
Contributor Author

unekinn commented May 20, 2026

@mimarz I have removed the SSR-specific code and added some examples – I finally managed to retain the focus border in the existing snapshots too 😅

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.

3 participants