Skip to content

Commit 293647a

Browse files
committed
Merge pull request angular-ui#353 from angular-ui/fix-choices-lesswatches
fix(choices): prevent unnecessary watches when dropdown is closed
2 parents 9f13358 + 9cf0870 commit 293647a

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/select.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,7 @@
885885
}
886886

887887
choices.attr('ng-repeat', RepeatParser.getNgRepeatExpression($select.parserResult.itemName, '$select.items', $select.parserResult.trackByExp, groupByExp))
888+
.attr('ng-if', '$select.open') //Prevent unnecessary watches when dropdown is closed
888889
.attr('ng-mouseenter', '$select.setActiveItem('+$select.parserResult.itemName +')')
889890
.attr('ng-click', '$select.select(' + $select.parserResult.itemName + ')');
890891

test/select.spec.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ describe('ui-select tests', function() {
144144
var choicesContainerEl = $(el).find('.ui-select-choices');
145145
expect(choicesContainerEl.length).toEqual(1);
146146

147+
openDropdown(el);
147148
var choicesEls = $(el).find('.ui-select-choices-row');
148149
expect(choicesEls.length).toEqual(8);
149150
});
@@ -367,12 +368,14 @@ describe('ui-select tests', function() {
367368
});
368369

369370
it('should set a disabled class on the option', function() {
370-
var option = $(this.el).find('.ui-select-choices-row div:contains("Wladimir")');
371-
var container = option.closest('.ui-select-choices-row');
372371

373372
openDropdown(this.el);
374373

374+
var option = $(this.el).find('.ui-select-choices-row div:contains("Wladimir")');
375+
var container = option.closest('.ui-select-choices-row');
376+
375377
expect(container.hasClass('disabled')).toBeTruthy();
378+
376379
});
377380
});
378381

@@ -398,11 +401,11 @@ describe('ui-select tests', function() {
398401
});
399402

400403
it('should set a disabled class on the option', function() {
404+
openDropdown(this.el);
405+
401406
var option = $(this.el).find('.ui-select-choices-row div:contains("Wladimir")');
402407
var container = option.closest('.ui-select-choices-row');
403408

404-
openDropdown(this.el);
405-
406409
expect(container.hasClass('disabled')).toBeTruthy();
407410
});
408411
});
@@ -429,11 +432,11 @@ describe('ui-select tests', function() {
429432
});
430433

431434
it('should set a disabled class on the option', function() {
435+
openDropdown(this.el);
436+
432437
var option = $(this.el).find('.ui-select-choices-row div:contains("Wladimir")');
433438
var container = option.closest('.ui-select-choices-row');
434439

435-
openDropdown(this.el);
436-
437440
expect(container.hasClass('disabled')).toBeTruthy();
438441
});
439442
});
@@ -485,9 +488,8 @@ describe('ui-select tests', function() {
485488
var el = createUiSelect();
486489
el.scope().$select.search = 't';
487490
scope.$digest();
488-
var choices = el.find('.ui-select-choices-row');
489-
490491
openDropdown(el);
492+
var choices = el.find('.ui-select-choices-row');
491493

492494
expect(choices.eq(0)).toHaveClass('active');
493495
expect(getGroupLabel(choices.eq(0)).text()).toBe('Foo');
@@ -844,6 +846,7 @@ describe('ui-select tests', function() {
844846
</ui-select>'
845847
);
846848

849+
openDropdown(el);
847850
expect($(el).find('.only-once').length).toEqual(1);
848851

849852

0 commit comments

Comments
 (0)