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

fix(UnderlineNav2): underline nav items' selected state can be managed by the app state & clean up #3361

Merged
merged 17 commits into from
Jul 20, 2023

Conversation

broccolinisoup
Copy link
Member

@broccolinisoup broccolinisoup commented Jun 5, 2023

Describe your changes here.

Closes #2865

State management issue

UnderlineNav items selected state was only manageable internally which wasn't an intentional decision, it was a bug. Folks reported the issue where they need to manage the selected state by the app state or separate navigation controls.

Clean up

Also took this PR as an opportunity to refactor and clean up some of the very early stage implementation details. I posted "Note for reviewers" comments to explain some of the not so obvious changes.

Screenshots

Before

Gif shows navigation elements and items are clicked to

Gif description: Example UnderlineNav navigation items are displayed with an overflow "More" menu. There is also a list of link items that manage the same navigation on the page. What is tested here is that when the navigation is managed by external controls (i.e. the list of link items not the UnderlineNav items), whether or not the UnderlineNav items reflect the current page by their selected state. UnderlineNav items are clicked to navigate to different pages and their selected state works fine however if the external controls are used to navigate to other routes, UnderlineNav items doesn't reflect the current page.

After

Kapture 2023-07-10 at 15 39 05

Gif description: Example UnderlineNav navigation items are displayed with an overflow "More" menu. There is also a list of link items that manage the same navigation on the page. What is tested here is that when the navigation is managed by external controls (i.e. the list of link items not the UnderlineNav items), whether or not the UnderlineNav items reflect the current page by their selected state. UnderlineNav items are clicked to navigate to different pages and their selected state works fine and now with the external controls are used to navigate to other routes, UnderlineNav items does reflect the current page.

Merge checklist

  • Added/updated tests
  • Added/updated documentation
  • Changes are SSR compatible
  • Tested in Chrome
  • Tested in Firefox
  • Tested in Safari
  • Tested in Edge

Take a look at the What we look for in reviews section of the contributing guidelines for more information on how we review PRs.

@changeset-bot
Copy link

changeset-bot bot commented Jun 5, 2023

🦋 Changeset detected

Latest commit: 96794b7

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
Copy link
Contributor

github-actions bot commented Jun 5, 2023

size-limit report 📦

Path Size
dist/browser.esm.js 102.36 KB (-0.38% 🔽)
dist/browser.umd.js 102.92 KB (-0.37% 🔽)

@broccolinisoup broccolinisoup temporarily deployed to github-pages June 5, 2023 06:24 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3361 June 5, 2023 06:24 Inactive
@broccolinisoup broccolinisoup temporarily deployed to github-pages June 5, 2023 07:45 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3361 June 5, 2023 07:46 Inactive
@broccolinisoup broccolinisoup temporarily deployed to github-pages June 5, 2023 08:23 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3361 June 5, 2023 08:23 Inactive
@broccolinisoup broccolinisoup temporarily deployed to github-pages July 10, 2023 00:00 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3361 July 10, 2023 00:01 Inactive
@@ -10,26 +9,16 @@ export const iconWrapStyles = {
marginRight: 2,
}

const smallVariantLinkStyles = {
Copy link
Member Author

Choose a reason for hiding this comment

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

Note for reviewers: These variants were considered in the initial version of the component but it is decided otherwise at the end. Removing them to reduce the clutter and complexity on the component and styles.

Comment on lines -25 to -27
// cariant and align are currently not in used. Keeping here until some design explorations are finalized.
variant?: 'default' | 'small'
align?: 'right'
Copy link
Member Author

Choose a reason for hiding this comment

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

Note for reviewers: variant and align were considered in the initial version of the component but it is being decided not to include them at the end. Removing them to reduce the clutter and complexity on the component and styles.

/**
* loading state for all counters. It displays loading animation for individual counters (UnderlineNav.Item) until all are resolved. It is needed to prevent multiple layout shift.
*/
loadingCounters?: boolean
afterSelect?: (event: React.MouseEvent<HTMLLIElement> | React.KeyboardEvent<HTMLLIElement>) => void
Copy link
Member Author

Choose a reason for hiding this comment

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

Note for reviewers: afterSelect was considered in the initial version of the component but it is being decided not to include it at the end. Removing it to reduce the clutter and complexity on the component

>(null)

const [iconsVisible, setIconsVisible] = useState<boolean>(true)

const afterSelectHandler = (event: React.MouseEvent<HTMLLIElement> | React.KeyboardEvent<HTMLLIElement>) => {
Copy link
Member Author

Choose a reason for hiding this comment

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

After removing the afterSelect, this is not needed.

@broccolinisoup broccolinisoup changed the title Bs/underline nav selected state fix(UnderlineNav2): underline nav items' selected state can be managed by the app state & clean up Jul 10, 2023
@broccolinisoup broccolinisoup temporarily deployed to github-pages July 10, 2023 04:11 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3361 July 10, 2023 04:11 Inactive
as={Component}
href={href}
onKeyPress={keyPressHandler}
onClick={clickHandler}
aria-current={ariaCurrent}
Copy link
Contributor

Choose a reason for hiding this comment

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

I saw some conversation about aria-current. It is the preferred method for accessibility, but I think it can be hard to control sometimes (at least that has been our experience so far with NavList). But maybe we can continue using it but handle the state of it somehow with more control? Or offer multiple solutions?

Copy link
Member Author

Choose a reason for hiding this comment

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

but I think it can be hard to control sometimes (at least that has been our experience so far with NavList)

Thanks for sharing this! I personally have mix feelings about this API and felt validated when you shared the feedback 😅 We changed the prop name from selected to aria-current to align with NavList. But if we already have feedback from NavList, maybe it is a good time to chat about in the Primer API session??

@github-actions github-actions bot temporarily deployed to storybook-preview-3361 July 18, 2023 06:34 Inactive
@broccolinisoup broccolinisoup temporarily deployed to github-pages July 18, 2023 06:35 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3361 July 18, 2023 06:36 Inactive
{responsiveProps.items}
{listLinks.map(listLink => {
return (
<Box
Copy link
Member Author

Choose a reason for hiding this comment

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

I moved the Box wrapper here to make UnderlineNav return <Link></Link> instead of <Box><Link></Link></Box to align with as PolymorphicForwardRefComponent<'a', UnderlineNavItemProps> but let me know if you have any concern. I am not 100% sure about that.

Copy link
Member

@joshblack joshblack left a comment

Choose a reason for hiding this comment

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

🥳

@broccolinisoup
Copy link
Member Author

And no aria-current needed because it will be handled internally?

As a user of this component, I would prefer the defaultSelected prop on the UnderlineNav.Item. This is to me much easier to understand than the aria-current one, but I don't know the implication on accessibility nor coherence with the other primer components.

@echarles Thanks for the feedback! We are thinking to go ahead with this implementation - I'll address that in a separate PR!

Merged via the queue into main with commit bea39c2 Jul 20, 2023
28 checks passed
@broccolinisoup broccolinisoup deleted the bs/underline-nav-selected-state branch July 20, 2023 07:07
@primer-css primer-css mentioned this pull request Jul 20, 2023
@echarles
Copy link
Contributor

@echarles Thanks for the feedback! We are thinking to go ahead with this implementation - I'll address that in a separate PR!

@broccolinisoup Sounds great. Now this is merged, I will give a try with the snapshots to confirm the state can be managed from the app.

@echarles
Copy link
Contributor

@broccolinisoup Sounds great. Now this is merged, I will give a try with the snapshots to confirm the state can be managed from the app.

Just tried with "@primer/react": "36.0.0-rc.59fbc025" published a few hours ago (the next major snapshot), but it dos not seem to work. I have the same behavior as before: Setting from the app aria-current to page does not change the selected item.

@broccolinisoup
Copy link
Member Author

Hi @echarles! The canary you are looking at it is the major release. The major change branch is behing a few commits from main. If you would like to test these changes, could you please try installing the canary version from the minor release branch? The last one seem to be 35.27.0-rc.7108ad52 Let me know how you go!

@echarles
Copy link
Contributor

echarles commented Jul 21, 2023

@broccolinisoup oh my bad. tbh I am confused with the major/minor snapshots. No worries, I will look in more details that point later.

Great news, 35.27.0-rc.7108ad52 works fine now for me. I can manage the nav items from the app. That was expected, but good to confirm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UnderlineNav v2 item can enter a selected non-current state
5 participants