Skip to content

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

@ralmidani

Description

@ralmidani

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions