-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
Allow NavLink to receive a children function #8164
Allow NavLink to receive a children function #8164
Conversation
This allows NavLink to work this way ```jsx <NavLink to="/home" className={({ isActive }) => isActive ? activeClassNames : inactiveClassNames}> {({ isActive }) => isActive ? <ActiveNavLinkContent /> : <InactiveNavLinkContent />} </NavLink> ```
style={({ isActive }) => | ||
isActive ? activeStyle : undefined | ||
className={({ isActive }) => | ||
isActive ? activeClassName : undefined |
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 changed this example to use className instead of style, so the API docs of NavLink now can have one example of style, className and children as functions.
this is technically already possible using a custom (Nav)Link component with the though I personally am not opposed to the changes here |
Let's do it, @sergiodxa, I fixed the conflicts, you want to sign the contributors.yml in this PR and I'll merge it? |
Thank you for signing the Contributor License Agreement. Let's get this merged! 🥳 |
Done! |
Fixed up the formatting for you, but it looks like there are a couple of test failures, unfortunately. |
Thank you for signing the Contributor License Agreement. Let's get this merged! 🥳 |
@timdorr I'm pretty sure it should be fixed now, could you run the workflow again? 🙏 |
…f request time (#8164) Co-authored-by: Mark Dalgleish <mark.john.dalgleish@gmail.com>
Right now the NavLink component has this useful className and style function support to change the styles if the link is active.
This is really cool, but one use case it doesn't support, but it's really easy to add support for, is what happens if inside the NavLink there are two, or more, elements and they need to change styles based on the isActive state, right now it's not really possible to detect that, specially when using utility CSS.
This PR adds support for that, which was also requested on the discussion #8080, copying the example from that discussion, now this is possible:
I also updated the
docs/api.md
to mention and show an example of this and the tests of the NavLink component to test this works.