-
Notifications
You must be signed in to change notification settings - Fork 217
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
fix: Tooltip describe variant using aria-description string instead of aria-describedby reference #2814
base: master
Are you sure you want to change the base?
fix: Tooltip describe variant using aria-description string instead of aria-describedby reference #2814
Conversation
The aria-description accepts a string equal to the value of the title prop.
Passing run #7439 ↗︎
Details:
Review all test suite changes for PR #2814 ↗︎ |
Trying a bracket notation just in case the camel-case 'ariaDescription' isn't supported yet.
…iamjstanton/canvas-kit into william-tooltip-description
This reverts commit 3d0ce3e.
Trying have.attr instead.
@@ -135,7 +135,7 @@ export function useTooltip<T extends Element = Element>({ | |||
|
|||
const targetProps = { | |||
// extra description of the target element for assistive technology | |||
'aria-describedby': type === 'describe' && visible ? id : undefined, | |||
'aria-description': type === 'describe' ? titleText : undefined, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is potentially breaking change, because now tooltip will require to have titleText
passed, but it's optional now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with Raisa. This would be breaking.
Also, shouldn't both be present since aria-describedby
points to the target of the element with the id and aria-description
is just describing what the element is with nothing pointing to it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is potentially breaking change, because now tooltip will require to have
titleText
passed, but it's optional now.
Does this mean title
prop was optional? Why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, shouldn't both be present since
aria-describedby
points to the target of the element with the id andaria-description
is just describing what the element is with nothing pointing to it?
No, for similar reasons why we discourage using both aria-labelledby
references and aria-label
strings on the same element. Browsers follow an algorithm to define a 1) accessible name
and 2) accessible description
for an element.
If aria-describedby
is used on an element, then an aria-description
string will be ignored and discarded by the browser.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
titleText
is optional in the useTooltip
hook, but not the title
in the Tooltip
component. titleText
was optional in useTooltip
because type="describe"
did not use the config. This change makes it so type="describe"
also uses the config. There is still the type="muted"
that doesn't use the titleText
config.
Now, title
is required by Tooltip
because it is the contents of the tooltip. OverflowTooltip
does not use title
because the contents of the target are the contents of the tooltip. An OverflowTooltip
uses the type="muted"
because a screen reader doesn't understand the concept of the ellipsis - to the screen reader, the full contents are exposed already. A screen dictation user will be able to target based on what content is already visible and not cut off - from there it is part of the design to make sure the most significant part of the target text is visible when overflowing.
@@ -28,10 +28,9 @@ describe('Tooltip', () => { | |||
fireEvent.mouseEnter(screen.getByText('Test Text')); // triggers the tooltip | |||
|
|||
jest.advanceTimersByTime(300); // advance the timer by the amount of delay time | |||
expect(screen.getByText('Test Text')).toHaveAttribute('aria-describedby'); | |||
expect(screen.getByText('Test Text')).toHaveAttribute('aria-description'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes sense to assert the contents of the attribute and not just the presence of it. The second parameter is the text that is expected.
|
||
const id = screen.getByText('Test Text').getAttribute('aria-describedby'); | ||
expect(screen.getByRole('tooltip')).toHaveAttribute('id', id); | ||
expect(screen.getByRole('tooltip')).toHaveAttribute('id'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it is important for the tooltip to have an id
at this point. This line should be removed. The id
was only used for the aria-describedby
.
Summary
Fixes: #2797
The
describe
variant of the tool tip relies onaria-describedby
attribute to assign the tool tip text to the accessible description of the target element. This only works when the tool tip is visible and present in the DOM, which only occurs when the element has focus. Screen readers can access web page elements without necessarily using keyboard focus, therefore, this variant didn't appear to always work reliably for screen reader users.Release Category
Components
Release Note
Replaces
aria-describedby
reference on the target element with anaria-description
stringChecklist
ready for review
has been added to PRFor the Reviewer
For the
describe
variant ofTooltip
, I replaced thearia-describedby
attribute witharia-description
and set thetitle
prop value string. Also, remove the check for if visible, so we can always assign this string to the description.Where Should the Reviewer Start?
useTooltip
custom hookAreas for Feedback? (optional)
Testing Manually
In the following scenarios, validate the issues cannot be reproduced and the tool tip text is always described without focusing the button elements.
Steps to reproduce the behavior:
With VoiceOver / MacOS:
With NVDA on Windows 11:
Screenshots or GIFs (if applicable)
No visual changes. Just
aria
attribute change.Thank You Gif (optional)