-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
*/ | ||
import { Button } from '@wordpress/components'; | ||
import { useState } from '@wordpress/element'; | ||
import { Icon, arrowLeft } from '@wordpress/icons'; | ||
|
||
/** | ||
* Internal dependencies | ||
|
@@ -48,6 +49,21 @@ const data = [ | |
id: 'child-2', | ||
parent: 'item-3', | ||
}, | ||
{ | ||
title: 'Nested Category', | ||
id: 'child-3', | ||
parent: 'item-3', | ||
}, | ||
{ | ||
title: 'Sub Child 1', | ||
id: 'sub-child-1', | ||
parent: 'child-3', | ||
}, | ||
{ | ||
title: 'Sub Child 2', | ||
id: 'sub-child-2', | ||
parent: 'child-3', | ||
}, | ||
{ | ||
title: 'External link', | ||
id: 'item-4', | ||
|
@@ -68,18 +84,14 @@ function Example() { | |
|
||
return ( | ||
<Navigation activeItemId={ active } data={ data } rootTitle="Home"> | ||
{ ( { level, levelItems, parentLevel, setActiveLevel } ) => { | ||
{ ( { level, levelItems, parentLevel, NavigationBackButton } ) => { | ||
return ( | ||
<> | ||
{ parentLevel && ( | ||
<Button | ||
isPrimary | ||
onClick={ () => | ||
setActiveLevel( parentLevel.id ) | ||
} | ||
> | ||
Back | ||
</Button> | ||
<NavigationBackButton> | ||
<Icon icon={ arrowLeft } /> | ||
{ parentLevel.title } | ||
</NavigationBackButton> | ||
) } | ||
<h1>{ level.title }</h1> | ||
<NavigationMenu> | ||
|
@@ -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 commentThe 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 I think this could also be done through props if you prefer ( There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Lets follow up, issue here: #24775 |
||
/> | ||
); | ||
} ) } | ||
|
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 forparentLevel
here instead of in the story: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.