-
-
Notifications
You must be signed in to change notification settings - Fork 403
Description
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
- One solution I have used successfully is to set
eventNametonever. 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. - Another approach would be for developers to subclass
LinkComponentand override theinit()method so it removes the event listener. But since the default event name isclick, this may have unintended side-effects if the developer does not changeeventNameto something likenever, as in the first approach.