Skip to content

SubNav: Update selected styles to only apply to data-selected='true' - #5797

Merged
broccolinisoup merged 2 commits into
mainfrom
fix-subnav-data-selected
Mar 21, 2025
Merged

SubNav: Update selected styles to only apply to data-selected='true'#5797
broccolinisoup merged 2 commits into
mainfrom
fix-subnav-data-selected

Conversation

@broccolinisoup

@broccolinisoupbroccolinisoup commented Mar 19, 2025

Copy link
Copy Markdown
Member

When the SunNav component is used in an environment with practical data, it is high likely that the selected attribute will be used in each SubNav children and their value will be conditionally rendered to true or false. Therefore the generated HTML will be

<adata-selected="false" aria-current="false" href="#nav1">Nav 1</a><adata-selected="true" aria-current="true" href="#nav2">Nav 2</a><adata-selected="false" aria-current="false" href="#nav3">Nav 3</a>

Currently the way we apply the selected styles are causing bug because the styles are applied to all links because all have data-selected property.

Here is an example from RL that shows the bug

sub nav had two items and both are highlighted with the selected color

There is currently no usage of SubNav at dotcom - this is why we probably didn't noticed the issue so far.

Changelog

New

Changed

  • Instead of selecting data-selected attribute to apply selected styles, I updated the code to select data-selected="true"

Removed

Rollout strategy

  • Patch release
  • Minor release
  • Major release; if selected, include a written rollout or migration plan
  • None; if selected, include a brief description as to why

Testing & Reviewing

If you could edit the Selected story so that each children have selected prop. You can repro the issue and with the change in this PR, you can verify the fix.

exportconstSelected=()=>{const[selectedItem,setSelectedItem]=React.useState('home')return(<SubNavaria-label="Main"><SubNav.Links><SubNav.Linkhref="#home"selected={selectedItem==='home'}>
Home
</SubNav.Link><SubNav.Linkhref="#documentation"selected={selectedItem==='documentation'}>
Documentation
</SubNav.Link><SubNav.Linkhref="#support"selected={selectedItem==='support'}>
Support
</SubNav.Link></SubNav.Links></SubNav>)}

Merge checklist

@changeset-bot

changeset-botBot commented Mar 19, 2025

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0ac27cd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
NameType
@primer/reactPatch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actionsgithub-actionsBot added the staff Author is a staff member label Mar 19, 2025
@github-actions

Copy link
Copy Markdown
Contributor

👋 Hi, this pull request contains changes to the source code that github/github depends on. If you are GitHub staff, we recommend testing these changes with github/github using the integration workflow. Thanks!

@github-actionsgithub-actionsBot added the integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm label Mar 19, 2025
@github-actions

github-actionsBot commented Mar 19, 2025

Copy link
Copy Markdown
Contributor

size-limit report 📦

PathSize
packages/react/dist/browser.esm.js105.9 KB (0%)
packages/react/dist/browser.umd.js106.14 KB (0%)

@broccolinisoupbroccolinisoup changed the title Only highlight data-selected='true'SubNav: Update selected styles to only apply to data-selected='true'Mar 19, 2025
@github-actions
github-actionsBot requested a deployment to storybook-preview-5797 March 19, 2025 04:18 Abandoned
@broccolinisoup
broccolinisoup marked this pull request as ready for review March 19, 2025 04:26
@broccolinisoup
broccolinisoup requested a review from a team as a code ownerMarch 19, 2025 04:26
@github-actions
github-actionsBottemporarily deployed to storybook-preview-5797 March 19, 2025 04:33 Inactive

@siddharthkpsiddharthkp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@broccolinisoup
broccolinisoup added this pull request to the merge queueMar 21, 2025
Merged via the queue into main with commit fbc6f97Mar 21, 2025
@broccolinisoup
broccolinisoup deleted the fix-subnav-data-selected branch March 21, 2025 03:14
@primerprimerBot mentioned this pull request Mar 21, 2025
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration-tests: recommendedThis change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpmstaffAuthor is a staff member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@broccolinisoup@siddharthkp