Skip to content
This repository has been archived by the owner on Dec 15, 2018. It is now read-only.

Link's active state is super opinionated #284

Open
manuphatak opened this issue Apr 23, 2018 · 1 comment
Open

Link's active state is super opinionated #284

manuphatak opened this issue Apr 23, 2018 · 1 comment

Comments

@manuphatak
Copy link

In the <Link> component, isActive could be a bit more robust.

const isActive = href.pathname === location.pathname;

activeProps is a cool idea, however, having more control over whether or not the link isActive might be a small improvement.

Example use case

I have a navbar with 3 links, let's call them "movies", "blogs", and "reports". Clicking movies takes you to an index page /movies. For /movies I want to say "movies" IS active. If I click to /movies/watchlist, for this case, I want to say "movies" is STILL active.

suggestions

  • an active prop
    const isActive = props.active ?? href.pathname === location.pathname;
  • or a maybe a callback that gets that href object
      // ...
      render(){
        // ...
        const isActive = props.isActive(href)
        // ...
      }
    // ...
    Link.defaultProps = { isActive: href => href.pathname === location.pathname  }
@mymattcarroll
Copy link

Would a pull request be welcome for this change? I would be more than happy to contribute.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants