Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes D2IQ-94906
Description
Background on the Issue
This initial issue arose from noticing a gray background on Tab Items in the UI after they've been clicked on. After looking into this issue, I discovered this behavior was coming from the
:focus
style set for the Tabs component upstream. It was an intentional style decision to handle keyboard navigation to display active focus.:focus
vs:focus-visible
After looking into the functionality of the
:focus
pseudo-class. I discovered:focus-visible
which applies the style when elements are interacted with via keyboard and not with pointer-events such as mouse clicks. This seemed like the perfect resolution for our situation. We do not want the gray background on click but we do want it for keyboard navigation to preserve accessibility.Resource: The :focus-visible Trick
React Tabs
After implementing
:focus-visible
over:focus
I noticed there was inconsistent behavior where it would still apply the gray background on click. I googled around a bit and found a related open issue with react-tabs. I noticed we were a major version behind on react-tabs. I updated that to see if it would resolve the issue, however it persisted. I ended up digging more into the react-tabs documentation and I found there were specific features of the component that were contributing to the unexpected focus behavior.The main culprit seemed to be
focusTabOnClick
which is by default set to true.Setting this property to false seemed to do the trick, and if you click the tab key keyboard navigation can still be initiated again. This change paired with using
:focus-visible
should prevent the not-so-aesthetically-pleasing gray background for pointer-events while maintaining proper accessibility features with keyboard navigation.Outline Discoveries
Another change you'll see is where I set
outline: 0
instead ofoutline: none
. I was looking into the differences between these two as I've seen both used in the past. Thought I would share what I learned there.According to MDN:
More detail on this question on StackOverflow.
Another comment mentioned this:
I opted for
outline: 0;
and I had to set it in both selector locations to prevent the focus ring outline.Further reading on outline and focus accessibility: http://www.outlinenone.com/
Which issue(s) does this PR relate to?
Testing
Interact with the Tabs component with keyboard navigation (tabs and arrows) compared to clicking on tabs.
Trade-offs
Screenshots
Tabs with keyboard navigation
Tabs with mouse clicks
Checklist