Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Mar 21, 2025

Conversation

broccolinisoup
Copy link
Member

@broccolinisoup broccolinisoup commented Mar 19, 2025

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

<a data-selected="false" aria-current="false" href="#nav1">Nav 1</a>
<a data-selected="true" aria-current="true" href="#nav2">Nav 2</a>
<a data-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.

export const Selected = () => {
  const [selectedItem, setSelectedItem] = React.useState('home')

  return (
    <SubNav aria-label="Main">
      <SubNav.Links>
        <SubNav.Link href="#home" selected={selectedItem === 'home'}>
          Home
        </SubNav.Link>
        <SubNav.Link href="#documentation" selected={selectedItem === 'documentation'}>
          Documentation
        </SubNav.Link>
        <SubNav.Link href="#support" selected={selectedItem === 'support'}>
          Support
        </SubNav.Link>
      </SubNav.Links>
    </SubNav>
  )
}

Merge checklist

Copy link

changeset-bot bot commented Mar 19, 2025

🦋 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
Name Type
@primer/react Patch

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-actions github-actions bot added the staff Author is a staff member label Mar 19, 2025
Copy link
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-actions github-actions bot 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
Copy link
Contributor

github-actions bot commented Mar 19, 2025

size-limit report 📦

Path Size
packages/react/dist/browser.esm.js 105.9 KB (0%)
packages/react/dist/browser.umd.js 106.14 KB (0%)

@broccolinisoup broccolinisoup 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-actions bot 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 owner March 19, 2025 04:26
Copy link
Member

@siddharthkp siddharthkp left a comment

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 queue Mar 21, 2025
Merged via the queue into main with commit fbc6f97 Mar 21, 2025
47 checks passed
@broccolinisoup broccolinisoup deleted the fix-subnav-data-selected branch March 21, 2025 03:14
@primer primer bot mentioned this pull request Mar 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm staff Author is a staff member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants