-
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
Changes from all commits
6dfdf53
a07bc64
e7aea1e
03f38ea
1abb9e8
a17ab42
f88e39a
5c64ab3
f2fb6f2
fe2d4b4
3d0ce3e
9ad189b
e15cf08
466bf2c
0e0d162
acd19b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import {Tooltip} from '@workday/canvas-kit-react/tooltip'; | ||
import {ListOfUploadedFiles} from './examples/Tooltips/ListOfUploadedFiles'; | ||
|
||
<Meta title="Examples/Tooltips" component={Tooltip} /> | ||
|
||
# Accessible Tooltip Examples | ||
|
||
## Using descriptive tooltips for repeated text buttons | ||
|
||
In this example, the "Delete" buttons are used repeatedly to reference the multiple files that have | ||
been uploaded to the web app. The text buttons already have an accessible name (a.k.a. label) | ||
derived from the button's inner text. The `describe` tooltip can be useful for providing more | ||
in-context description for both low vision sighted users and screen reader users without overriding | ||
the button name "Delete". | ||
|
||
<ExampleCodeBlock code={ListOfUploadedFiles} /> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React from 'react'; | ||
|
||
import {DeleteButton} from '@workday/canvas-kit-react/button'; | ||
import {Flex} from '@workday/canvas-kit-react/layout'; | ||
import {Heading, Text} from '@workday/canvas-kit-react/text'; | ||
import {Tooltip} from '@workday/canvas-kit-react/tooltip'; | ||
import {trashIcon} from '@workday/canvas-system-icons-web'; | ||
|
||
const files = ['Cover Letter.docx', 'Resume.docx', 'Portfolio.pptx', 'Portrait.png']; | ||
|
||
const listStyles = { | ||
alignItems: 'center', | ||
width: '35rem', | ||
}; | ||
|
||
const deleteBtnStyle = { | ||
marginLeft: 'auto', | ||
}; | ||
|
||
export const ListOfUploadedFiles = () => { | ||
return ( | ||
<> | ||
<Heading size="medium">Uploaded Files:</Heading> | ||
<Flex as="ul" gap="1rem" flexDirection="column"> | ||
{files.map(i => ( | ||
<Flex as="li" style={listStyles}> | ||
<Text>{i}</Text> | ||
<Tooltip type="describe" title={i}> | ||
<DeleteButton icon={trashIcon} style={deleteBtnStyle}> | ||
Delete | ||
</DeleteButton> | ||
</Tooltip> | ||
</Flex> | ||
))} | ||
</Flex> | ||
</> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 commentThe 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 |
||
}); | ||
jest.clearAllTimers(); | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,22 @@ | ||
import React from 'react'; | ||
|
||
import {DeleteButton} from '@workday/canvas-kit-react/button'; | ||
import {DeleteButton, SecondaryButton, TertiaryButton} from '@workday/canvas-kit-react/button'; | ||
import {Tooltip} from '@workday/canvas-kit-react/tooltip'; | ||
import {Flex} from '@workday/canvas-kit-react/layout'; | ||
import {chartConfigIcon} from '@workday/canvas-system-icons-web'; | ||
|
||
export const DescribeType = () => { | ||
return ( | ||
<Tooltip type="describe" title="The service will restart after this action"> | ||
<DeleteButton>Delete</DeleteButton> | ||
</Tooltip> | ||
<Flex gap="s"> | ||
<Tooltip type="describe" title="Search using additional criteria"> | ||
<TertiaryButton icon={chartConfigIcon}>Advanced Search</TertiaryButton> | ||
</Tooltip> | ||
<Tooltip type="describe" title="Create saved search"> | ||
<SecondaryButton>Save</SecondaryButton> | ||
</Tooltip> | ||
<Tooltip type="describe" title="The service will restart after this action"> | ||
<DeleteButton>Delete</DeleteButton> | ||
</Tooltip> | ||
</Flex> | ||
); | ||
}; |
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 andaria-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.
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.
No, for similar reasons why we discourage using both
aria-labelledby
references andaria-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 anaria-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 theuseTooltip
hook, but not thetitle
in theTooltip
component.titleText
was optional inuseTooltip
becausetype="describe"
did not use the config. This change makes it sotype="describe"
also uses the config. There is still thetype="muted"
that doesn't use thetitleText
config.Now,
title
is required byTooltip
because it is the contents of the tooltip.OverflowTooltip
does not usetitle
because the contents of the target are the contents of the tooltip. AnOverflowTooltip
uses thetype="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.