You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Make tooltips accessible to screen readers via persistent aria-describedby (#3333)
While testing #3332 with VO in Safari I noticed that there is no way to
get a screen reader to read a tooltip on a button. It appears this is
because they only appear in the a11y tree when the tooltip is open (it
appears visually but not to the screen reader for some reason). So
instead we add a permanent describedby to the button. It works!
I considered having it reuse the tooltip div as the `sr-only`
description when the tooltip is closed to avoid having two copies of the
description in the DOM, but basically it seems like Floating UI wants
you to do conditional rendering. In order to keep the div around and
_not_ conditionally render it, we would instead end up doing kinda
gnarly stuff like this:
```tsx
<div
ref={open ? refs.setFloating : undefined}
className={open ? 'ox-tooltip …' : 'sr-only'}
aria-hidden={open ? undefined : true}
>
{content}
</div>
```
It can work, but it requires a more complicated integration with
Floating UI lifecycle stuff. Seems fine to duplicate the div instead and
keep the tooltip rendering on the simple happy path.
- https://floating-ui.com/docs/react#anchoring
- https://floating-ui.com/docs/usefloating#whileelementsmounted
0 commit comments