-
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: Improve navigateToMenu and Chevron Usage #25251
Comments
Just a thought here. |
🤔 To be honest, I kinda think that a prop like What would the "navigator item" component be like? How would it differ from
They would probably end up being extremely similar, except for one prop, and for the presence of a chevron icon. But regardless of the implementation: would separate components make the life easier for consumers? { items.map( item =>
<NavigationItem href={ item.url } navigateToItem={ ! item.url && item.id } />
) }
{ items.map( item =>
item.url
? <NavigationItem href={ item.url } />
: <NavigationItemCategory navigateToItem={ item.id } />
) } To be clear, my proposal for this would be to keep the one single component, and, if
|
I think it would be difficult to come up with a good name for the second component. I don't think If we go for two different components, best would be for the const NavigationItemCategory = ({ ...props }) => <NavigationItem {...props} /> But after all, I agree with Jacopo, we shouldn't split the component into two. |
Thanks for considering the possibilities, I think you all are right and its best to keep a single component.
Currently, the chevron is ignored with Custom content. Should we allow |
I'm cool to close this issue in this case, thanks to all for the input. |
"It may interfere with a uniform look and feel" I agree, it would be great to be as flexible as possible. How about something like this:
Edit: Removed code screenshots and created a PR instead #25402 |
I'm personally a bit wary of rendering functions as they are often needlessly complicated to use. 🤔 To recap:
I agree about the inconsistent look, although I'm also inclined to say that a generic component should allow a certain degree of freedom. I'm inclined to think that we should allow
if ( ! children ) {
return ( <Button onClick={ onItemClick } /> );
}
if ( navigateToMenu ) {
return ( <div
onClick={ onItemClick }
onKeyDown={ event => {
if ( ENTER === event.keyCode || SPACE === event.keyCode ) {
onItemClick();
}
} }
role="button"
tabIndex="0"
>{ children }</div> );
}
return children; |
This would be an advanced usage of the component, so in this case I'd say it's fine. It's a very well known pattern IMO. We can also think about using a render prop instead: <NavigationItem
renderItem={ ( { navigateToMenu } ) => (
<div onClick={ () => navigateToMenu( 'menu2' ) }>
Custom
</div>
) }
/> |
On the topic of accepting a function to render, it would seem to me that we only currently have theoretical use-cases at this point? If that is indeed the case, I would suggest not including it in the API surface for the time being. It will be easy enough to add it later, if a compelling use-case presents itself, but difficult-to-impossible to remove should it turn out to have been a poor decision. And already knowing that it could be a source of visual confusion would make me very hesitant. |
I agree with @mattwiebe. What do y'all think of keeping the current behaviour and discuss it again if/when we can't avoid it? To recap, the current behaviour is:
const [ activeMenu, setActiveMenu ] = useState( 'root' );
<Navigation activeMenu={ activeMenu } onActivateMenu={ setActiveMenu }>
<NavigationMenu title="Home">
<NavigationItem
item="default-navigation"
title="Default Navigation"
navigateToMenu="sub-menu"
/>
<NavigationItem item="custom-navigation">
<Button onClick={ () => setActiveMenu( 'sub-menu' ) }>
Custom Navigation
</Button>
</NavigationItem>
</NavigationMenu>
</Navigation> |
Sounds good to me 👍 |
Yup, nice one here team. I'm happy with the conclusion you've come to that the current behaviour is sufficient and we can deal with a use case when it comes up. I'll close this and we can come back to it when the need arises. |
Check if the
NavigationItem
definingnavigateToMenu
can actually be used to navigate to a hierarchical menu, and therefore needs a chevron.gutenberg/packages/components/src/navigation/item.js
Line 66 in 668a710
Examples:
href
it becomes an external link, which would clash with the internal navigation.See #25057 (comment)
The text was updated successfully, but these errors were encountered: