Accessibility of Tooltip with disabled items
@siriwatknp is already working on this.
Since Jun 20, 2022.
- Dominant language
- JavaScript
- Stars
- 99.1k
- Forks
- 32.5k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 106
Description
Duplicates
- I have searched the existing issues
Latest version
- I have tested the latest version
Summary 💡
I'm having trouble figuring out how to make accessibility work well with a Tooltip with disabled items.
If I follow the docs:
<Tooltip title="Delete">
<span>
<IconButton disabled>
<DeleteIcon />
</IconButton>
</span>
</Tooltip>
then Tooltip adds the label to the span instead of the button, and I get warnings from accessibility tools like Axe and Lighthouse that a span element probably shouldn't have an aria-label and that the button doesn't have an aria-label.
I can address the second issue by duplicating the label:
<Tooltip title="Delete">
<span>
<IconButton aria-label="Delete" disabled>
<DeleteIcon />
</IconButton>
</span>
</Tooltip>
But then I'm having to duplicate text, and I have two elements with the same label, which may introduce other accessibility concerns. (For example, React Testing Library's screen.findByLabelText is no longer happy, and I assume some screen readers would read it twice.)
Is there a clean way of fixing this? The only solution I can think of is for Tooltip to add some sort of wrap or allowDisabled or WrapperComponent prop that would cause it to use a span wrapper itself; that way, it could know the "real" child and inject the label or description there, while still having the wrapper it needs to let it work with a disabled child.
Examples 🌈
See https://codesandbox.io/s/lucid-sound-oh0mnx?file=/src/App.tsx for an example.
Motivation 🔦
See above.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.