Thread of 5 posts1 min read
Accessible tooltips are incredibly hard
Accessible tooltips are incredibly hard to build as a generic component in React (and I assume other component-based frameworks) It's way harder than just linking the tooltip text to the trigger with aria-describedby
Firstly, what if the trigger supplies a description of it's own? Should Tooltip content A: Override it B: Merge with it C: Yield to it I'd say B is the best default behaviour because A & B throw away context
But this is actually impossible to implement in React without relying on mutation observers. And even that relies on being able to get a ref to the trigger's HTML node, which isn't always possible
On top of that it's not even clear what the best default experience is, because there are always use cases where having an accessible label is required and where it absolutely shouldn't exist
For example if a tooltip just shows the full value of a piece of truncated text, it shouldn't be linked with aria-describedby lest the label be announced twice by screen readers In this use case the tooltip only exists for users _not_ using a screen reader