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

Accessibility of Tooltip with disabled items #33182

Open
2 tasks done
joshkel opened this issue Jun 16, 2022 · 6 comments
Open
2 tasks done

Accessibility of Tooltip with disabled items #33182

joshkel opened this issue Jun 16, 2022 · 6 comments
Assignees
Labels
accessibility a11y component: tooltip This is the name of the generic UI component, not the React module! new feature New feature or request

Comments

@joshkel
Copy link
Contributor

joshkel commented Jun 16, 2022

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.

@joshkel joshkel added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jun 16, 2022
@mnajdova mnajdova self-assigned this Jun 20, 2022
@siriwatknp siriwatknp assigned siriwatknp and unassigned mnajdova Jun 20, 2022
@siriwatknp siriwatknp added new feature New feature or request accessibility a11y component: tooltip This is the name of the generic UI component, not the React module! and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jun 21, 2022
@siriwatknp
Copy link
Member

siriwatknp commented Jun 21, 2022

@michaldudak Would focusableWhenDisabled solves this use case?

@michaldudak
Copy link
Member

It could, yes as it works by replacing the disabled attribute with aria-disabled. It's not available yet in Material UI, though.

@emlai
Copy link
Contributor

emlai commented Nov 11, 2022

We're running into this issue as well, and accessibility is very important to us. Is there a workaround for this?

@zhaowh3613
Copy link

any update for this issue?

@sag1v
Copy link

sag1v commented Apr 17, 2023

@joshkel A11y wise, is there a spec on how to deal with tooltips of disabled buttons?

@joshkel
Copy link
Contributor Author

joshkel commented Apr 17, 2023

@sag1v I'm not aware of any:

Based on that, it sounds like the suggestion above of using focusableWhenDisabled / aria-disabled could work.

However, to clarify, my issue is less "MUI's Tooltip isn't accessible when used with a disabled item," it's more "MUI's recommendation for letting Tooltip work with a disabled item interferes with accessibility, even if the item is enabled." In other words, I'm okay with accessibility of disabled items being not ideal (since it's not well-specified and there are significant tradeoffs in how to handle it), but it seems undesirable for core accessibility features of enabled items to suffer in the process. Personally, if Tooltip had some sort of wrap or allowedDisabled or disabled option that allowed it to render the equivalent of

    <IconButton aria-label="Delete" onMouseEnter={showTooltip} onMouseLeave={hideTooltip}>
      <DeleteIcon />
    </IconButton>

for enabled components and

<span onMouseEnter={showTooltip} onMouseLeave={hideTooltip}>
    <IconButton aria-label="Delete" disabled>
      <DeleteIcon />
    </IconButton>
</span>

for disabled components, I'd be happy. (E.g., maybe Tooltip could gain its own disabled prop that causes it to render a span itself while continuing to forward aria-label, etc. to its child button, instead of making the caller provide a span that Tooltip has to treat as opaque.)

This is all my personal opinion - I'm not an a11y expert and could easily be missing considerations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accessibility a11y component: tooltip This is the name of the generic UI component, not the React module! new feature New feature or request
Projects
None yet
Development

No branches or pull requests

7 participants