Remove the href from disabled TopNav items (#408) - #435
Merged
Conversation
A disabled TopNavItem still rendered a live href, so middle-click and "Open link in new tab" bypassed the React click guard and navigated to the disabled destination. Null the href (plus target/rel) when disabled, matching Link and SideNavItem. The anchor still renders, with aria-disabled and tabIndex -1 as before. Claude-Session: https://claude.ai/code/session_01XFkkvUQfynGRedEYDNxKoY
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #408
Problem
TopNavItempassedhrefunconditionally, even when disabled. The existing mitigations —aria-disabled,tabIndex={-1}, and anonClickpreventDefault— don't remove the link: middle-click and "Open link in new tab" bypass the React click guard entirely and navigate to the disabled destination.This also made TopNav the outlier in the library:
LinkandSideNavItemboth null the href when disabled.Fix
href={isDisabled ? undefined : href}, and droptarget/relalongside it (they are meaningless without an href, and this matchesLink). The anchor still renders witharia-disabledandtabIndex={-1}as before, so nothing else about the rendered output changes.Tests
Added a regression test asserting a disabled item's anchor has no
href,target, orrelattribute. The disabled TopNav items in the existing Storybook story cover this visually.https://claude.ai/code/session_01XFkkvUQfynGRedEYDNxKoY