-
Notifications
You must be signed in to change notification settings - Fork 535
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
Conversation
🦋 Changeset detectedLatest commit: 96794b7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
size-limit report 📦
|
@@ -10,26 +9,16 @@ export const iconWrapStyles = { | |||
marginRight: 2, | |||
} | |||
|
|||
const smallVariantLinkStyles = { |
There was a problem hiding this comment.
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.
// cariant and align are currently not in used. Keeping here until some design explorations are finalized. | ||
variant?: 'default' | 'small' | ||
align?: 'right' |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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>) => { |
There was a problem hiding this comment.
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.
as={Component} | ||
href={href} | ||
onKeyPress={keyPressHandler} | ||
onClick={clickHandler} | ||
aria-current={ariaCurrent} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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??
…apper out of the UnderlineNavItem component
{responsiveProps.items} | ||
{listLinks.map(listLink => { | ||
return ( | ||
<Box |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🥳
@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. |
Just tried with |
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 |
@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, |
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 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
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
Take a look at the What we look for in reviews section of the contributing guidelines for more information on how we review PRs.