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

[UnderlineNav] : Keep selected item always visible #2361

Merged
merged 15 commits into from
Oct 7, 2022

Conversation

broccolinisoup
Copy link
Member

@broccolinisoup broccolinisoup commented Sep 23, 2022

Closes #1296

Storybook link: https://primer-1475f2ddc1-13348165.drafts.github.io/storybook/?path=/story/components-underlinenav

This PR is for keeping UnderlineNav's selected link always visible. This means;

  • If an item selected and the window is resized or a when a page is loaded and the selected item stays out of the viewport, component always make sure to keep this item on the list and not be pulled in to the dropdown menu. It does it by interrupting the natural order of the list and appending this selected item to the list as the last item.
  • If an item from the dropdown menu is selected, component moves this item out of the menu, appends it to the list and pulls as many item as required into the menu to make room for the selected item. (Natural order is interrupted here as well)

Screen Recordings

Screen.Recording.2022-09-30.at.10.44.04.pm.mov

Please provide before/after screenshots for any visual changes

Merge checklist

  • Added/updated tests
  • Added/updated documentation
  • 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.

@broccolinisoup broccolinisoup added the skip changeset This change does not need a changelog label Sep 23, 2022
@changeset-bot
Copy link

changeset-bot bot commented Sep 23, 2022

🦋 Changeset detected

Latest commit: 043dbe3

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 Minor

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 Sep 23, 2022

size-limit report 📦

Path Size
dist/browser.esm.js 77.19 KB (+0.01% 🔺)
dist/browser.umd.js 77.81 KB (+0.01% 🔺)

@broccolinisoup broccolinisoup temporarily deployed to github-pages September 23, 2022 05:36 Inactive
@broccolinisoup broccolinisoup temporarily deployed to github-pages September 26, 2022 04:43 Inactive
@broccolinisoup broccolinisoup temporarily deployed to github-pages September 26, 2022 05:33 Inactive
@broccolinisoup broccolinisoup marked this pull request as ready for review September 26, 2022 08:41
@broccolinisoup broccolinisoup requested review from a team and colebemis September 26, 2022 08:41
@broccolinisoup broccolinisoup changed the title WIP: [UnderlineNav] : Keep selected item always visible [UnderlineNav] : Keep selected item always visible Sep 26, 2022
Base automatically changed from broccolinisoup/underlineNav-overflow to main September 28, 2022 03:19
@broccolinisoup broccolinisoup temporarily deployed to github-pages September 28, 2022 03:52 Inactive
@broccolinisoup broccolinisoup temporarily deployed to github-pages September 29, 2022 08:45 Inactive
@broccolinisoup broccolinisoup temporarily deployed to github-pages September 29, 2022 12:28 Inactive
@broccolinisoup broccolinisoup temporarily deployed to github-pages September 30, 2022 02:11 Inactive
@broccolinisoup broccolinisoup temporarily deployed to github-pages September 30, 2022 02:25 Inactive
@broccolinisoup
Copy link
Member Author

Hi @danielguillan 👋🏼 Keeping the selected item visible is ready for you to review 😊 This PR includes both overflow behaviour as well as the loading counter states. Feel free to review and test them as well here.
Please see the storybook link here and on the description as well and I'll update the docs next week 📝 Looking forward to hearing your thought!

@@ -106,14 +105,19 @@ const overflowEffect = (
for (const [index, child] of childArray.entries()) {
if (index < numberOfItemsPossibleWithMoreMenu) {
items.push(child)
// keeping selected item always visible.
} else if (child.props.selected) {
Copy link
Member

Choose a reason for hiding this comment

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

yay ssr friendly hack 👍

@danielguillan
Copy link
Contributor

This looks great!

My only feedback is that we should persist the item order when selecting visible items. That is, when we swap a selected item to make it visible and the user then selects an already visible item, we should keep the current (updated) item order instead of restoring the original one. This is to prevent the visual change that happens away from the user's cursor which can be confusing.

Always.visible.item.swap.mp4

In the recording above, when we click "Actions", the "Insights" item shouldn't be swapped back with "Projects". "Insights" should still be the last item. Same for when we click "Pull requests", the "Settings" item shouldn't be swapped back with "Projects".

@broccolinisoup
Copy link
Member Author

This looks great!

My only feedback is that we should persist the item order when selecting visible items. That is, when we swap a selected item to make it visible and the user then selects an already visible item, we should keep the current (updated) item order instead of restoring the original one. This is to prevent the visual change that happens away from the user's cursor which can be confusing.

Always.visible.item.swap.mp4
In the recording above, when we click "Actions", the "Insights" item shouldn't be swapped back with "Projects". "Insights" should still be the last item. Same for when we click "Pull requests", the "Settings" item shouldn't be swapped back with "Projects".

👋🏼 @danielguillan Thanks so much for your review! No worries, I wasn't sure about that ordering behaviour and it makes sense to reduce the layout shifts. I'll revert it now

@broccolinisoup broccolinisoup temporarily deployed to github-pages October 4, 2022 05:57 Inactive
@broccolinisoup broccolinisoup temporarily deployed to github-pages October 4, 2022 20:35 Inactive
@broccolinisoup broccolinisoup temporarily deployed to github-pages October 5, 2022 09:01 Inactive
@broccolinisoup broccolinisoup removed the skip changeset This change does not need a changelog label Oct 6, 2022
@broccolinisoup broccolinisoup temporarily deployed to github-pages October 6, 2022 04:24 Inactive
@broccolinisoup broccolinisoup temporarily deployed to github-pages October 6, 2022 04:35 Inactive
Copy link
Collaborator

@pksjce pksjce left a comment

Choose a reason for hiding this comment

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

Lets go!

@broccolinisoup broccolinisoup temporarily deployed to github-pages October 7, 2022 00:16 Inactive
@broccolinisoup broccolinisoup merged commit ba7cf92 into main Oct 7, 2022
@broccolinisoup broccolinisoup deleted the keep-selected-item-visible branch October 7, 2022 00:23
@primer-css primer-css mentioned this pull request Oct 7, 2022
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.

None yet

5 participants