-
-
Notifications
You must be signed in to change notification settings - Fork 5
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
Active className for <A>? #20
Comments
Hey, you can use |
Apologies for the hasty comment, I see what you mean now. I'd be happy to add this to the library. Feel free to send a PR. Just keep in mind that it should also be a separate tag (wrapper over |
Yes, it requires a subscription to the I wrote a component which looks like this: import React from 'react';
import { router } from 'kea-router'
import { useValues } from 'kea';
export default function NavLink(props = {}) {
let { location: { pathname } } = useValues(router);
pathname = pathname.toLowerCase();
const isActive = props.href.toLowerCase() === pathname ||
(!props.exact &&
pathname.startsWith(props.href) &&
pathname.charAt(props.href.length) === "/");
let clsName = (props.className || '');
if (isActive) {
clsName += " active";
}
return <a
{...props}
onClick={(event) => {
if (!props.target) {
event.preventDefault()
router.actions.push(props.href) // router is mounted automatically, so this is safe to call
}
props.onClick && props.onClick(event)
}}
className={clsName}
/>
} There's an additional I'll send a PR next later this week. |
As far as I understood, there is no way to add a className for active
<A>
s (like React-router's<NavLink>
).Is this something in the roadmap? I'm happy to add a pull request if that's something worth adding to the library.
The text was updated successfully, but these errors were encountered: