Skip to content

Commit b27344a

Browse files
authored
Merge pull request #15265 from bekzod/compute-active
[BUGFIX] fixed issue when passing `false` to `activeClass` would break things
2 parents 88a9a97 + fe751ed commit b27344a

File tree

2 files changed

+58
-7
lines changed

2 files changed

+58
-7
lines changed

packages/ember-glimmer/lib/components/link-to.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ const LinkComponent = EmberComponent.extend({
545545
}
546546
}),
547547

548-
_computeActive(routerState) {
548+
_isActive(routerState) {
549549
if (get(this, 'loading')) { return false; }
550550

551551
let routing = get(this, '_routing');
@@ -563,7 +563,7 @@ const LinkComponent = EmberComponent.extend({
563563

564564
for (let i = 0; i < currentWhen.length; i++) {
565565
if (routing.isActiveForRoute(models, resolvedQueryParams, currentWhen[i], routerState, isCurrentWhenSpecified)) {
566-
return get(this, 'activeClass');
566+
return true;
567567
}
568568
}
569569

@@ -584,31 +584,37 @@ const LinkComponent = EmberComponent.extend({
584584
@property active
585585
@private
586586
*/
587-
active: computed('attrs.params', '_routing.currentState', function computeLinkToComponentActive() {
587+
active: computed('attrs.params', '_active', function computeLinkToComponentActiveClass() {
588588
let currentState = get(this, '_routing.currentState');
589589
if (!currentState) { return false; }
590590

591-
return this._computeActive(currentState);
591+
return this.get('_active') ? get(this, 'activeClass') : false;
592+
}),
593+
594+
_active: computed('_routing.currentState', function computeLinkToComponentActive() {
595+
let currentState = get(this, '_routing.currentState');
596+
if (!currentState) { return false; }
597+
return this._isActive(currentState);
592598
}),
593599

594600
willBeActive: computed('_routing.targetState', function computeLinkToComponentWillBeActive() {
595601
let routing = get(this, '_routing');
596602
let targetState = get(routing, 'targetState');
597603
if (get(routing, 'currentState') === targetState) { return; }
598604

599-
return !!this._computeActive(targetState);
605+
return this._isActive(targetState);
600606
}),
601607

602608
transitioningIn: computed('active', 'willBeActive', function computeLinkToComponentTransitioningIn() {
603-
if (get(this, 'willBeActive') === true && !get(this, 'active')) {
609+
if (get(this, 'willBeActive') === true && !get(this, '_active')) {
604610
return 'ember-transitioning-in';
605611
} else {
606612
return false;
607613
}
608614
}),
609615

610616
transitioningOut: computed('active', 'willBeActive', function computeLinkToComponentTransitioningOut() {
611-
if (get(this, 'willBeActive') === false && get(this, 'active')) {
617+
if (get(this, 'willBeActive') === false && get(this, '_active')) {
612618
return 'ember-transitioning-out';
613619
} else {
614620
return false;

packages/ember/tests/helpers/link_to_test/link_to_transitioning_classes_test.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ moduleFor('The {{link-to}} helper: .transitioning-in .transitioning-out CSS clas
2020

2121
this.aboutDefer = RSVP.defer();
2222
this.otherDefer = RSVP.defer();
23+
this.newsDefer = RSVP.defer();
2324
let _this = this;
2425

2526
this.router.map(function() {
2627
this.route('about');
2728
this.route('other');
29+
this.route('news');
2830
});
2931

3032
this.add('route:about', Route.extend({
@@ -39,11 +41,18 @@ moduleFor('The {{link-to}} helper: .transitioning-in .transitioning-out CSS clas
3941
}
4042
}));
4143

44+
this.add('route:news', Route.extend({
45+
model() {
46+
return _this.newsDefer.promise;
47+
}
48+
}));
49+
4250
this.addTemplate('application',`
4351
{{outlet}}
4452
{{link-to 'Index' 'index' id='index-link'}}
4553
{{link-to 'About' 'about' id='about-link'}}
4654
{{link-to 'Other' 'other' id='other-link'}}
55+
{{link-to 'News' 'news' activeClass=false id='news-link'}}
4756
`);
4857

4958
this.visit('/');
@@ -53,6 +62,7 @@ moduleFor('The {{link-to}} helper: .transitioning-in .transitioning-out CSS clas
5362
super.teardown();
5463
this.aboutDefer = null;
5564
this.otherDefer = null;
65+
this.newsDefer = null;
5666
}
5767

5868
['@test while a transition is underway'](assert) {
@@ -88,6 +98,41 @@ moduleFor('The {{link-to}} helper: .transitioning-in .transitioning-out CSS clas
8898
assertHasNoClass(assert, $about, 'ember-transitioning-out');
8999
assertHasNoClass(assert, $other, 'ember-transitioning-out');
90100
}
101+
102+
['@test while a transition is underway with activeClass is false'](assert) {
103+
let $index = this.$('#index-link');
104+
let $news = this.$('#news-link');
105+
let $other = this.$('#other-link');
106+
107+
$news.click();
108+
109+
assertHasClass(assert, $index, 'active');
110+
assertHasNoClass(assert, $news, 'active');
111+
assertHasNoClass(assert, $other, 'active');
112+
113+
assertHasNoClass(assert, $index, 'ember-transitioning-in');
114+
assertHasClass(assert, $news, 'ember-transitioning-in');
115+
assertHasNoClass(assert, $other, 'ember-transitioning-in');
116+
117+
assertHasClass(assert, $index, 'ember-transitioning-out');
118+
assertHasNoClass(assert, $news, 'ember-transitioning-out');
119+
assertHasNoClass(assert, $other, 'ember-transitioning-out');
120+
121+
this.runTask(() => this.newsDefer.resolve());
122+
123+
assertHasNoClass(assert, $index, 'active');
124+
assertHasNoClass(assert, $news, 'active');
125+
assertHasNoClass(assert, $other, 'active');
126+
127+
assertHasNoClass(assert, $index, 'ember-transitioning-in');
128+
assertHasNoClass(assert, $news, 'ember-transitioning-in');
129+
assertHasNoClass(assert, $other, 'ember-transitioning-in');
130+
131+
assertHasNoClass(assert, $index, 'ember-transitioning-out');
132+
assertHasNoClass(assert, $news, 'ember-transitioning-out');
133+
assertHasNoClass(assert, $other, 'ember-transitioning-out');
134+
}
135+
91136
});
92137

93138
moduleFor(`The {{link-to}} helper: .transitioning-in .transitioning-out CSS classes - nested link-to's`, class extends ApplicationTestCase {

0 commit comments

Comments
 (0)