Skip to content
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 support for an active class on the Link component #23

Closed
jeroenverfallie opened this issue Nov 10, 2015 · 7 comments
Closed

Add support for an active class on the Link component #23

jeroenverfallie opened this issue Nov 10, 2015 · 7 comments

Comments

@jeroenverfallie
Copy link

When on the route, add an active class to links associated with the route.

     <Link
        signal={this.props.signals.somethingHappened}
        params={{foo: 'bar'}}
        activeClass="active"
        className="my-class"
      >Click me</Link>

A special case would be params.. sometimes you want the active class to show only when the params match, other times you want to only match the base.

@Guria
Copy link
Collaborator

Guria commented Nov 11, 2015

@christianalfoni

  • So we have to subscribe to url changes from store and we need access to controller instance. We can get it from context now, but I not sure if it always would there.
  • Also we have to know which path in store subscribe to, since it could be changed in router options. We could access router instance at controller.service.router.

We need to decide how we would subscribe to url changes. Also I would suggest to split component onto smart and dumb one.

@Guria
Copy link
Collaborator

Guria commented Nov 11, 2015

var 1

  • expose controller.service.router.getUrl() which would be called in controller.on("change") callback.

var 2

  • expose controller.service.router.on('change', callback)

var 3
...

@christianalfoni
Copy link
Collaborator

Hm, I think we should just listen to changes on controller and check path using the option on the router. That way time travelling etc. will work as expected.

Though this is starting to get very complex. A stated by @jeroenverfallie , sometimes you want the link to be active as parent of a path, but other times you do not want that. Only when it is the actual url.

I think we should maybe use a function here:

 <Link
        signal={this.props.signals.somethingHappened}
        params={{foo: 'bar'}}
        activeClass="active"
        isActive={function (routes, route) { // matching logic}
        className="my-class"
      >Click me</Link>

So by default it needs a perfect match, but you can decide whatever you want to make it active. Not quite sure about this.

Guria referenced this issue in cerebral-legacy/cerebral-module-router Nov 11, 2015
@Guria
Copy link
Collaborator

Guria commented Nov 11, 2015

We thought a little. This change brings extra complexity and doesn't fit well React/Flux ideas about state driven UI.
We suggest to use something like <Link className={this.props.page === 'home' ? 'active' : 'notactive'}/>. Routing will affect some path in store passed as this.props.page and className would be changed accordingly.

We must document such approach as best practice.

@NervosaX
Copy link
Contributor

NervosaX commented Feb 9, 2016

Perhaps this ticket should be closed @Guria?

@Guria
Copy link
Collaborator

Guria commented Feb 9, 2016

Let it stay until it covered in docs

@Guria
Copy link
Collaborator

Guria commented Mar 3, 2016

closed in favor to cerebral-legacy/cerebral-module-router#82

@Guria Guria closed this as completed Mar 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants