-
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
Add custom nav link props to Navigation component #24570
Add custom nav link props to Navigation component #24570
Conversation
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.
Very nice. I noted an opportunity to simplify logic
{ | ||
title: 'Custom link', | ||
id: 'item-4', | ||
linkTag: 'a', |
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.
Can we make an assumption here that if an href
is found, use a anchor tag?
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.
Now that I think about it, Button
already has this logic built in.
const Tag = href !== undefined && ! trulyDisabled ? 'a' : 'button'; |
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.
Ya, button already includes this logic; the use of a
here is purely for demonstration, though we could easily swap this with another tag if you think it would be more appropriate.
Using linkTag
allows us to pass a prop like the Link
component or some other custom component to integrate with various routers.
There are 3 types of nav actions:
To differentiate between the first two can be as simple as the presence of an The 3rd type provides navigation in whatever context of the consuming app's routing. A callback could be sufficient as you can do something like |
I think the
I'm in favor of allowing both. The use case here might be a link click, but also wanting to fire an event, such as tracking.
Seems like it does offer some a11y support, but I would let consumers use this in the
Agreed- that's the intention of the |
Can you rebase this one now that the two previous PRs are merged? |
d8506c6
to
52cf7ef
Compare
Indeed it does. If you let return (
<MenuItemUI className={ classes }>
- <LinkTagName
+ <Button
className={ classes }
href={ href }
onClick={ handleClick }
@@ -56,7 +56,7 @@ const NavigationMenuItem = ( props ) => {
</Text>
{ badge && <BadgeUI>{ badge }</BadgeUI> }
{ hasChildren ? <Icon icon={ chevronRight } /> : null }
- </LinkTagName>
+ </Button>
</MenuItemUI>
);
}; In 8864e06 I take it one step further by adding a |
Just for visibility from above:
The |
{ LinkComponent ? ( | ||
<LinkComponent | ||
className={ classes } | ||
onClick={ handleClick } |
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.
Missing href
in here. I think the old implementation simplifies the props logic here a bit.
{ | ||
title: 'Internal link', | ||
id: 'item-5', | ||
LinkComponent: CustomRouterLink, |
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 addition 👍
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 like the composite approach here. I did realize after the fact that your approach did indeed allow passing of a custom component. I think we will need some good documentation around LinkComponent
, and the entire config for that matter.
* Allow custom link tag and props for menu items * Let Button handle logic and add LinkComponent * Add back in link tag const to allow sharing of props Co-authored-by: Paul Sealock <psealock@gmail.com>
* Allow custom link tag and props for menu items * Let Button handle logic and add LinkComponent * Add back in link tag const to allow sharing of props Co-authored-by: Paul Sealock <psealock@gmail.com>
* Allow custom link tag and props for menu items * Let Button handle logic and add LinkComponent * Add back in link tag const to allow sharing of props Co-authored-by: Paul Sealock <psealock@gmail.com>
Description
NOTE: Branched from
add/nav-badges
and will need a rebase pending its merge.Allows passing the link tag name as well as additional props to this component. Allows consumers to bring their own routing components and link tags.
Screenshots
Testing
npm run storybook:dev
.