Skip to content

Commit

Permalink
[BUGIFX] link-to active class applied when params change
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmit committed Jan 12, 2018
1 parent ee85052 commit 1facdd0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/ember-glimmer/lib/components/link-to.ts
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ const LinkComponent = EmberComponent.extend({
return this.get('_active') ? get(this, 'activeClass') : false;
}),

_active: computed('_routing.currentState', function computeLinkToComponentActive(this: any) {
_active: computed('_routing.currentState', 'attrs.params', function computeLinkToComponentActive(this: any) {
let currentState = get(this, '_routing.currentState');
if (!currentState) { return false; }
return this._isActive(currentState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,30 @@ moduleFor('Link-to component', class extends ApplicationTest {
});
}

['@test re-computes active class when params change'](assert) {
let controller;

this.addTemplate('application', '{{link-to "foo" routeName}}');

this.add('controller:application', Controller.extend({
init() {
this._super(...arguments);
controller = this;
},
routeName: 'index'
}));

this.router.map(function() {
this.route('bar', { path: '/bar' });
});

return this.visit('/bar').then(() => {
assert.equal(this.firstChild.contains('active'), false);
this.runTask(() => set(controller, 'routeName', 'bar'));
assert.equal(this.firstChild.contains('active'), true);
});
}

['@test escaped inline form (double curlies) escapes link title']() {
this.addTemplate('application', `{{link-to title 'index'}}`);
this.add('controller:application', Controller.extend({
Expand Down

0 comments on commit 1facdd0

Please sign in to comment.