view_components
view_components copied to clipboard
Improving screen reader support for tooltip
Context
- In https://github.com/primer/view_components/pull/1256, we swapped
hiddentovisibility: hidden. The motivation is to workaround a surfaced incompatibility with the accessibility API and the web component API that prevents ahiddenelement from serving as an accessible name or description until thehiddenis removed once. It is expected forhiddenelements to label or describe another element. This seems to be a bug specific to custom elements usage. visibility:hiddenhelped us get around the issue and ensured labeling/description relations are established correctly for screen reader users. However, it introduced layout issues that is apparent when tooltips are on the far rights side of the page. This is due to fact that the tooltip will take up the full space. The tooltip isn't positioned where it needs to be until it is interacted with. We don't want to position tooltip on page load because doing so will cause performance issues if a page has hundreds of tooltips.
Suggestion
- use the
sr-onlyclass to hide or show the tooltip to sighted users - always keep
aria-hiddenon the tooltip when it is a label type to reduce verbosity