Skip to content

Commit d0f320a

Browse files
committed
[BUGFIX beta] Allow boolean values for current-when
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 #12344 did not seem to actually fix this particular bug. Related issues: - #12512 - #12630 (fix was not merged) - #12296
1 parent 2d9e3aa commit d0f320a

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -549,8 +549,12 @@ const LinkComponent = EmberComponent.extend({
549549
let routing = get(this, '_routing');
550550
let models = get(this, 'models');
551551
let resolvedQueryParams = get(this, 'resolvedQueryParams');
552-
553552
let currentWhen = get(this, 'current-when');
553+
554+
if (typeof currentWhen === 'boolean') {
555+
return currentWhen ? get(this, 'activeClass') : false;
556+
}
557+
554558
let isCurrentWhenSpecified = !!currentWhen;
555559
currentWhen = currentWhen || get(this, 'qualifiedRouteName');
556560
currentWhen = currentWhen.split(' ');

packages/ember/tests/helpers/link_to_test.js

+16
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,22 @@ moduleFor('The {{link-to}} helper - nested routes and link-to arguments', class
527527
assert.equal(this.$('#link3.active').length, 0, 'The link is not active since current-when does not contain the active route');
528528
}
529529

530+
['@test The {{link-to}} helper supports boolean values for current-when'](assert) {
531+
this.router.map(function(match) {
532+
this.route('index', { path: '/' }, function() {
533+
this.route('about');
534+
});
535+
this.route('item');
536+
});
537+
538+
this.addTemplate('index', `<h3>Home</h3>{{outlet}}`);
539+
this.addTemplate('index.about', `{{#link-to 'item' id='other-link' current-when=true}}ITEM{{/link-to}}`);
540+
541+
this.visit('/about');
542+
543+
assert.equal(this.$('#other-link').length, 1, 'The link is active since current-when is true');
544+
}
545+
530546
['@test The {{link-to}} helper defaults to bubbling'](assert) {
531547
this.addTemplate('about', `
532548
<div {{action 'hide'}}>

0 commit comments

Comments
 (0)