Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tooltip labeling #3094

Merged
merged 16 commits into from
Aug 28, 2024
Merged

Tooltip labeling #3094

merged 16 commits into from
Aug 28, 2024

Conversation

KenAJoh
Copy link
Collaborator

@KenAJoh KenAJoh commented Aug 14, 2024

Description

Resolves #3067

Really liked how MUI handled this interaction:
https://mui.com/material-ui/react-tooltip/#accessibility

By default now, the child element (i.e Button that Tooltip wraps around) will get title-attrb set to the Tooltip content when closes. When open, it will remove title and use aria-describedby. By doing this the Tooltip will act as an extra description for the element, without overriding the button-content itself.

If the user sets describeChild={false} now, the child element will instead get aria-label set to the Tooltip-content. This will remain static between open-states. By doing this the Tooltip will always act as the label/name for the child-element. This is especially useful for Icon-buttons and similar elements.

After merge i will update Tooltip docs with some notes on this prop and how to use it.

Discussion

I have now set the prop describeChild to default True, closer to todays implementation to reduce breaking changes. Issue is it still adds a small potential "breaking" change since

title attrb is added

  • Wrong use of tooltip today, example those who print "kopiert" or a state update in the tooltip today will incorrectly label the element by default
  • Might break some tests based on how they were locating elements before (low chance i recon)

aria-describedby is not merged with child-prop

  • If child-element has aria-describedby, it will not merge with Tooltip aria-describedby. Might argue this shouldn't have been implemented in the first place, but might break some tests

Should describeChild be default false?

Since adding this change might have some breaking changes anyways, should it just be set to default false? All current Tooltip child-elements will get an aria-label with the Tooltip contents, but might argue that would be an improvement all around except in a few cases. Some tests might break, and some teams will have to update their Tooltip. Does this change fit into one of those small major-updates we have discussed?

Copy link

changeset-bot bot commented Aug 14, 2024

🦋 Changeset detected

Latest commit: 8f7d4d5

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

This PR includes changesets to release 7 packages
Name Type
@navikt/ds-react Major
@navikt/ds-css Major
@navikt/ds-tokens Major
@navikt/ds-tailwind Major
@navikt/aksel-icons Major
@navikt/aksel Major
@navikt/aksel-stylelint Major

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

Copy link
Contributor

github-actions bot commented Aug 14, 2024

Storybook demo

Endringer til review: 5

b5c7cba5e | 88 komponenter | 139 stories

@JulianNymark
Copy link
Contributor

I'll have to check more when I get to the office, but looks good so far. Also if the choice is between breaking change anyway vs breaking change + improvements I'd go for the latter 🙌

@larseirikhansen
Copy link
Contributor

Do i understand this correct: The question is whether describeChild should be false or true by default on Tooltip?

If describeChild is set to true by default, it's less breaking:

  • a button "kopier meg" with a (bad) tooltip "kopiert!" will read "kopier meg kopiert!", so you also get the text content of the button read. Should be used when the button has text content.

If describeChild is set to false by default, it potentially has more breaking changes:

  • a button "kopier meg" with a (bad) tooltip "kopiert!" will only read "kopiert!", so it high jacks the screen reader content.

@KenAJoh
Copy link
Collaborator Author

KenAJoh commented Aug 14, 2024

Do i understand this correct: The question is whether describeChild should be false or true by default on Tooltip?

If describeChild is set to true by default, it's less breaking:

  • a button "kopier meg" with a (bad) tooltip "kopiert!" will read "kopier meg kopiert!", so you also get the text content of the button read. Should be used when the button has text content.

If describeChild is set to false by default, it potentially has more breaking changes:

  • a button "kopier meg" with a (bad) tooltip "kopiert!" will only read "kopiert!", so it high jacks the screen reader content.

Yep thats a perfect summary of change/issue 💯

* Important: This will default to false in future major-versions
* @default true
*/
describeChild?: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is "describesChild" clearer? (Added "s")

Copy link
Contributor

Choose a reason for hiding this comment

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

I notice the comment for this will then have lied about the future
"This will default to false in future major-versions" (so we should remove that 😅 )

@HalvorHaugan
Copy link
Contributor

My only "concern" about setting it to false by default, is that devs might not remember (or know) to change it to true when needed. Having it true by default will sometimes lead to repeated info for screen readers, but at least they will not miss any info? But I guess that's an edge case.

Also, what about voice control? With describeChild=false it would be very important that the text in the Tooltip starts with the name text as the button does. (Btw, how is a11y assured for voice control users when only an icon is visible?)

@KenAJoh
Copy link
Collaborator Author

KenAJoh commented Aug 14, 2024

Having it true by default will sometimes lead to repeated info for screen readers, but at least they will not miss any info? But I guess that's an edge case.

Based on the implementations looked through, i would argue that more info is left out for the screen-readers today with the avid use of Tooltip around non-interactive elements. By setting default to false, those cases would be "fixed" to a certain degree. But i guess it's a give and take situation where both options with either default true or false each have some positives and negatives. Adding some more specific documentation with a post or two on Slack while keeping default to true might be the least intrusive tho.

Also, what about voice control? With describeChild=false it would be very important that the text in the Tooltip starts with the name text as the button does. (Btw, how is a11y assured for voice control users when only an icon is visible?)

Good question, i can do some testing and ask Morten 👍

@KenAJoh
Copy link
Collaborator Author

KenAJoh commented Aug 14, 2024

@HalvorHaugan Did some testing with Mac voicecontrols:
Sandbox for reference

Screen.Recording.2024-08-14.at.13.46.28.mov
  • For icons using title or aria-label acts the same
  • For buttons with text and aria-label, aria-label takes precedence
  • For buttons with text and title, text takes precedence

Since its shows a tooltip with the "accessible name" that is needed to trigger button i can't see it being a problem. Unless... the text is super long. As for that case, there is a setting where instead of labels, each element gets a number to remove this problem all together.

Screen.Recording.2024-08-14.at.13.52.48.mov

This is ofc only based on my testing so will need to talk to someone more experienced for how this is actually done.

@KenAJoh
Copy link
Collaborator Author

KenAJoh commented Aug 15, 2024

As long as the user follows this guideline: https://www.w3.org/TR/WCAG22/#label-in-name when combining a visual label with a tooltip (aria-label) it should pass requirements. This is not something we can control, but will need to document on the Tooltip documentation.

@HalvorHaugan
Copy link
Contributor

As long as the user follows this guideline: https://www.w3.org/TR/WCAG22/#label-in-name when combining a visual label with a tooltip (aria-label) it should pass requirements. This is not something we can control, but will need to document on the Tooltip documentation.

Yes, I think my point was that it's not intuitive that the tooltip "overrides" the content by default. But I guess it's fine since this is typically not a problem based on how it's normally used, combined with good docs 👍

aksel.nav.no/website/pages/eksempler/tooltip/labeling.tsx Outdated Show resolved Hide resolved
Comment on lines 13 to 24
<Tooltip content="Skriv ut dokument" describesChild>
<Button icon={<ArrowUpIcon aria-hidden />} />
</Tooltip>
<Tooltip content="Skriv ut dokument" placement="right">
<Button icon={<ArrowRightIcon title="demo knapp" />} />
<Tooltip content="Skriv ut dokument" placement="right" describesChild>
<Button icon={<ArrowRightIcon aria-hidden />} />
</Tooltip>
<Tooltip content="Skriv ut dokument" placement="bottom">
<Button icon={<ArrowDownIcon title="demo knapp" />} />
<Tooltip content="Skriv ut dokument" placement="bottom" describesChild>
<Button icon={<ArrowDownIcon aria-hidden />} />
</Tooltip>
<Tooltip content="Skriv ut dokument" placement="left">
<Button icon={<ArrowLeftIcon title="demo knapp" />} />
<Tooltip content="Skriv ut dokument" placement="left" describesChild>
<Button icon={<ArrowLeftIcon aria-hidden />} />
</Tooltip>
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't describesChild be false in these cases? 🤔 (Same in some of the other examples)

Copy link
Collaborator Author

@KenAJoh KenAJoh Aug 26, 2024

Choose a reason for hiding this comment

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

Looks like i flipped it when adding it to demo 🙈 I updated defaultValue to false since this will be a breaking change anyways, and updated the examples 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

Did you forget to update aksel.nav.no/website/pages/eksempler/togglegroup/with-tooltip.tsx?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Messed up the rebase 💥

Co-authored-by: Halvor Haugan <83693529+HalvorHaugan@users.noreply.github.com>
Copy link
Contributor

Choose a reason for hiding this comment

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

Major?

Text should be updated.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👍 Updated to major and added a TODO. Will write a section for v7 here https://aksel.nav.no/grunnleggende/kode/migrering.

For now i will create a feature-branch we can merge v7 changes into and change the base of this branch to that one.

@KenAJoh KenAJoh changed the base branch from main to aksel-v7 August 26, 2024 15:14
@KenAJoh KenAJoh added the Aksel-V8 Oppgaven er relatert til ny major-release label Aug 26, 2024
@KenAJoh KenAJoh merged commit 65d4802 into aksel-v7 Aug 28, 2024
5 checks passed
@KenAJoh KenAJoh deleted the tooltip-describeChild branch August 28, 2024 11:42
HalvorHaugan added a commit that referenced this pull request Sep 13, 2024
* Tooltip labeling (#3094)

* feat: Better labeling of Tooltip

* feat: Better keyshortcuts for screenreaders in Tooltip

* memo: Updated story

* bug: Better error logging for example-parsing

* refactor: describeChild -> describesChild

* fire: Removed extra story

* bug: removed extra tabIndex

* memo: Update Tooltip demo description

* Update aksel.nav.no/website/pages/eksempler/tooltip/labeling.tsx

Co-authored-by: Halvor Haugan <83693529+HalvorHaugan@users.noreply.github.com>

* refactor: Updated defaultValue for describesChild

* bug: removed Tooltip prop from ToggleGroup

---------

Co-authored-by: Halvor Haugan <83693529+HalvorHaugan@users.noreply.github.com>

* Tailwind: Fixed 'screen' -> 'screens' bug to properly adopt breakpoints. (#3119)

* 💥 Screen -> Screens in tailwind-config

* refactor: Adopt updated screens-config in Aksel.nav.no project

* Icons: Removed old and renamed icons (#3120)

* 💥 Removed renamed icons

* ErrorSummary: Add fallback for heading + better focus handling (#3140)

Co-authored-by: Ken <ken.aleksander@gmail.com>
Co-authored-by: Ken <26967723+KenAJoh@users.noreply.github.com>

Co-authored-by: Halvor Haugan <83693529+HalvorHaugan@users.noreply.github.com>

* feat: Added composeEventHandlers to onFocus in ErrorSummary

* memo: Removed inaccurate description for tooltip demo

* feat: Omitted tabIndex from ErrorSummary

---------

Co-authored-by: Ken <26967723+KenAJoh@users.noreply.github.com>
Co-authored-by: Ken <ken.aleksander@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Aksel-V8 Oppgaven er relatert til ny major-release diskusjon 🧐 klar for gjennomgang 🔍
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Innspill til komponent]: <Tooltip> UU og Axe
4 participants