Skip to content

Commit

Permalink
[BUGFIX beta] Allow boolean values for current-when
Browse files Browse the repository at this point in the history
As the docs say, `A link will be active if current-when is true`.
Looks like this might have been broken since 1.13 and emberjs#12344
did not seem to actually fix this particular bug.

Related issues:

- emberjs#12512
- emberjs#12630 (fix was not merged)
- emberjs#12296
  • Loading branch information
whatthewhat committed Jan 18, 2017
1 parent 516e93c commit e174b05
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/ember-glimmer/lib/components/link-to.js
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,12 @@ const LinkComponent = EmberComponent.extend({
let routing = get(this, '_routing');
let models = get(this, 'models');
let resolvedQueryParams = get(this, 'resolvedQueryParams');

let currentWhen = get(this, 'current-when');

if (typeof currentWhen === 'boolean') {
return currentWhen ? get(this, 'activeClass') : false;
}

let isCurrentWhenSpecified = !!currentWhen;
currentWhen = currentWhen || get(this, 'qualifiedRouteName');
currentWhen = currentWhen.split(' ');
Expand Down
19 changes: 19 additions & 0 deletions packages/ember/tests/helpers/link_to_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,25 @@ QUnit.test('The {{link-to}} helper supports multiple current-when routes', funct
equal(jQuery('#link3.active', '#qunit-fixture').length, 0, 'The link is not active since current-when does not contain the active route');
});

QUnit.test('The {{link-to}} helper supports boolean values for current-when', function() {
Router.map(function(match) {
this.route('index', { path: '/' }, function() {
this.route('about');
});

this.route('item');
});

setTemplate('index', compile('<h3>Home</h3>{{outlet}}'));
setTemplate('index/about', compile("{{#link-to 'item' id='other-link' current-when=true}}ITEM{{/link-to}}"));

bootApplication();

run(() => router.handleURL('/about'));

equal(jQuery('#other-link.active', '#qunit-fixture').length, 1, 'The link is active since current-when is true');
});

QUnit.test('The {{link-to}} helper defaults to bubbling', function() {
setTemplate('about', compile("<div {{action 'hide'}}>{{#link-to 'about.contact' id='about-contact'}}About{{/link-to}}</div>{{outlet}}"));
setTemplate('about/contact', compile("<h1 id='contact'>Contact</h1>"));
Expand Down

0 comments on commit e174b05

Please sign in to comment.