USWDS - usa-skipnav: Ensure visual focus indicator persists on skipnav target #6475
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.
Summary
Fixed a bug in the
usa-skipnavcomponent where the visual focus indicator on the target element would disappear after activation. This change ensures the focus indicator remains visible by removing an explicit JavaScript outline removal, improving accessibility for keyboard users.Breaking change
This is not a breaking change.
Related issue
Closes #6474
Related pull requests
NA
Preview link
Old Functionality (Focus Indicator Disappears):
https://github.com/user-attachments/assets/63405f9d-01bf-4383-bc65-1945c67610e9
New Functionality (Focus Indicator Persists):
https://github.com/user-attachments/assets/4e9ff6e5-81e7-4949-b548-6974fc77455e
Previewed locally using Storybook. The
skipnavcomponent now correctly maintains visual focus on the target element.Problem statement
Currently, when a user activates a
skipnavlink (e.g., "Skip to main content"), the target element (like<main id="main-content">) receives programmatic focus, but the visual focus indicator is immediately removed by a line of JavaScript (target.style.outline = "0";). This prevents users, particularly those relying on keyboard navigation, from visually confirming where their focus has landed on the page, negatively impacting accessibility and user orientation.Solution
This PR fixes the disappearing focus indicator by removing the line
target.style.outline = "0";from thesetTabindexfunction inpackages/usa-skipnav/src/index.js. By removing this explicit outline suppression, the browser's default focus outline or USWDS-defined CSS focus styles will now correctly apply and remain visible on theskipnavtarget element. This ensures that keyboard users receive the necessary visual feedback when navigating via skip links.Major changes
Removed
target.style.outline = "0";frompackages/usa-skipnav/src/index.js.Testing and review
Manually tested by activating
skipnavlinks in a local Storybook environment. Confirmed that the target element (e.g.,main-content) receives focus and that a visual focus indicator (browser default or USWDS style) is now present and persists until focus is moved again.To reproduce: Navigate to a page with a
skipnavcomponent. Activate the skip link (e.g., by tabbing to it and pressing Enter or clicking). Observe that the target element now visibly displays a focus ring.Ran
npm run lintandnpm run prettier:jsandnpm testsuccessfully.