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

Allow developers to declare a "dummy" link-to #106

Closed
ralmidani opened this issue Dec 6, 2015 · 6 comments
Closed

Allow developers to declare a "dummy" link-to #106

ralmidani opened this issue Dec 6, 2015 · 6 comments

Comments

@ralmidani
Copy link

Problem

Currently, there is no simple, foolproof way to declare a "dummy" link-to, i.e. one which appears on the page, receives the active class when its route (or a child route thereof) is current, but is never invoked as a result any event being triggered.

Real-world scenario

Developers want to create dropdown menus with links to child routes. They depend on Ember to add a class when the route or one of its children is current (the default class is "active") and have styles be applied by a CSS framework such as Twitter's Bootstrap. In the case of bootstrap, this is usually done with a link-to where tagName is set to li, and a plain a element is embedded within the li. By default, clicking on the li will transition to its url, although developers simply want clicking to open a dropdown menu containing child links, allowing users to navigate to a more specific part of the app.

Proposed solution

Allow developers to set an argument indicating the link-to should never be invoked. This could be done with a parameter named (for example) neverInvoke which defaults to false and indicates whether the link-to is for display only.

In the init() method for LinkComponent, if neverInvoke is true, eventName will not be bound to the _invoke() method.

Drawbacks

This increases the API surface area of link-to, and adds some complexity to the implementation of LinkComponent. Also, the number of people needing this feature is unknown.

Alternative solutions

  1. One solution I have used successfully is to set eventName to never. This feels like a hack, and developers will have to be directed to naming the event in a way which ensures it will never be triggered. Also, while the performance hit of attaching one "dead" event listener is negligible, allowing this to proliferate throughout large apps seems irresponsible.
  2. Another approach would be for developers to subclass LinkComponent and override the init() method so it removes the event listener. But since the default event name is click, this may have unintended side-effects if the developer does not change eventName to something like never, as in the first approach.
@ralmidani
Copy link
Author

@mixonic would love to hear from you since you've raised an issue related to link-to and bootstrap before.

@rlivsey
Copy link

rlivsey commented Dec 6, 2015

I think the plan here to have a router service and then decompose the existing link-to helper into multiple helpers, eg the url-for helper and I expect a is-active helper of some sort using this service.

@rwjblue
Copy link
Member

rwjblue commented Dec 6, 2015

Yes, I believe @rlivsey is correct here.

See discussion in #92 and #95.

@mixonic
Copy link
Sponsor Member

mixonic commented Dec 6, 2015

Yup!

@ralmidani
Copy link
Author

Thanks for the responses.

I took a look at #92 and #95.

So the plan is to enable lower-level helpers which can replace the monolithic link-to helper. Is that an accurate summary?

@rwjblue
Copy link
Member

rwjblue commented Dec 6, 2015 via email

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