Revisit :focus-visible
Background
There are two commonly held perspectives for applying focus indicators to active elements; focus always visible regardless of input method, and focus visible determined by browser heuristics. I've historically been solidly focus always visible without exception, however, after going through Practical Accessibility from Sara Soueidan, perspective from accessibility experts (references below), team member perspectives, competitive analysis, and personal experience, I'd like to lean into :focus-visible.
What is :focus-visible
The
:focus-visiblepseudo-class applies while an element matches the:focuspseudo-class and the UA (User Agent) determines via heuristics that the focus should be made evident on the element. (Many browsers show a "focus ring" by default in this case.) (Source)
Browser support is good for the latest version of all major browsers, and there are simple fallback techniques to account for other browsers.
In Understanding SC 2.4.7: Focus Visible (Level AA) the Technique C45: Using CSS :focus-visible to provide keyboard focus indication is listed as a sufficient technique to satisfy the success criteria.
Proposal
- Use
:focus-visibleto style focus rings based on UA heuristics. - Consider if there are any instances where a mouse user would still need to have visible focus.
- Update Pajamas documentation.
📓 Reference
Issues & MRs
- gitlab#297353 (closed)
- #1219 (closed)
- #2198 (closed)
- gitlab-org/gitlab-services/design.gitlab.com!3753 (merged)
- !2687 (merged)
Other
- https://www.sarasoueidan.com/blog/focus-indicators
- https://developer.paciellogroup.com/blog/2018/03/focus-visible-and-backwards-compatibility/
- https://developer.mozilla.org/en-US/docs/Web/CSS/:focus-visible
- https://www.w3.org/WAI/WCAG22/Techniques/css/C45
- https://caniuse.com/?search=:focus-visible
- https://www.w3.org/TR/selectors-4/#the-focus-visible-pseudo
- https://css-tricks.com/managing-user-focus-with-focus-visible
- https://css-tricks.com/almanac/pseudo-selectors/f/focus-visible/
- https://daverupert.com/2024/01/focus-visible-love/