-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Navigation Component: Remove setActiveLevel child function arg #24704
Navigation Component: Remove setActiveLevel child function arg #24704
Conversation
Size Change: 0 B Total Size: 1.16 MB ℹ️ View Unchanged
|
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.
Nice work on this, Paul; I like the idea of simplifying some of the exposed logic in this component.
I left some comments for discussion as I am a little concerned about limiting the ability to externally control the state of this component.
@@ -91,7 +103,6 @@ function Example() { | |||
onClick={ ( selected ) => | |||
setActive( selected.id ) | |||
} | |||
setActiveLevel={ setActiveLevel } |
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.
One concern I have with removing this is that we limit much of the control over the state of this menu externally.
For example, imagine a WooCommerce helper page that says "Navigate to the Settings
section in the menu." We can allow the click handler of the Settings
link to navigate the side menu. Tutorial based components may also want to make use of this function.
I think this could also be done through props if you prefer (if ( activeLevelId !== prevActiveLevelid ) { setActiveLevel( activeLevelId ) }
), but I'd like to not restrict control here too much.
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.
Just so I understand what you're suggesting: the feature you'd like to keep is the ability to externally control the navigation component without actually navigating.
I can see why that might be useful in some circumstances. What if we exposed an optional top level prop called activeLevel
? That would accomplish the same result without having to expose a function. That brings its own challenges we'd need to document, but I think it would be more straightforward than using setActiveLevel
function.
What do you think?
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.
Sure! That sounds like a good strategy to me. Do you want to do it here or should we tackle in a follow-up?
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.
Lets follow up, issue here: #24775
@@ -39,13 +41,24 @@ const Navigation = ( { activeItemId, children, data, rootTitle } ) => { | |||
} | |||
}, [] ); | |||
|
|||
const NavigationBack = ( { children: backButtonChildren } ) => { | |||
return ( |
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.
If we do keep this component instead of passing setActiveLevel
maybe we should also include the logic for parentLevel
here instead of in the story:
if ( ! parentLevel ) {
return null;
}
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.
Thats a good addition (a897c42). And the implementation can also do logic like this, so I'll leave the check in the story.
{ parentLevel ? (
<NavigationBackButton>
<Icon icon={ arrowLeft } />
{ parentLevel.title }
</NavigationBackButton>
) : (
<Button>Do something else</Button>
) }
@@ -39,13 +41,24 @@ const Navigation = ( { activeItemId, children, data, rootTitle } ) => { | |||
} | |||
}, [] ); | |||
|
|||
const NavigationBack = ( { children: backButtonChildren } ) => { |
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.
Semantic nitpick:
const NavigationBack = ( { children: backButtonChildren } ) => { | |
const NavigationBackButton = ( { children: backButtonChildren } ) => { |
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.
Nice, fixed in 279bd0c
1c2111b
to
aa9d063
Compare
a897c42
to
b4a02f6
Compare
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.
Thanks for those additions! This is testing well for me and LGTM 👍
…ress#24704) * remove setActiveLevel from public api * change to NavigationBackButton * return null for backButton if no parentLevel
* Navigation Component: Remove setActiveLevel child function arg (#24704) * remove setActiveLevel from public api * change to NavigationBackButton * return null for backButton if no parentLevel * Navigation Component: Expose __experimentalNavigation component (#24706) * Expose __experimentalNavigation component * fix typo * expose menut and menu-item as well * Loop over navigation levels and wrap with animate * Use map and set to organize items and levels * Simplify level and item logic * Remove unnecessary key prop * Fix parent level assignment * Add back in key prop to force animation * Use useMemo to map item data Co-authored-by: Paul Sealock <[email protected]>
* Navigation Component: Remove setActiveLevel child function arg (#24704) * remove setActiveLevel from public api * change to NavigationBackButton * return null for backButton if no parentLevel * Navigation Component: Expose __experimentalNavigation component (#24706) * Expose __experimentalNavigation component * fix typo * expose menut and menu-item as well * Loop over navigation levels and wrap with animate * Use map and set to organize items and levels * Simplify level and item logic * Remove unnecessary key prop * Fix parent level assignment * Add back in key prop to force animation * Use useMemo to map item data Co-authored-by: Paul Sealock <[email protected]>
Fixes #24671
Description
Remove
setActiveLevel
fromNavigation
child function arguments.setActiveLevel
exposes the internal mechanism for keeping track of waterfall state, or in other words where the user is as they navigate the tree. The consuming app doesn't need to use it and exposing it only causes confusion.Its functionality is useful for the "Back" button but allowing the consuming app to compose the contents as they choose requires its use. This PR seeks a middle ground by passing down a component called
NavigationBack
as a child function argument.Its use now encapsulates
setActiveLevel
while allowing maximum composition.How has this been tested?
npm run storybook:dev
to see the Navigation component function.Screenshots
Checklist: