Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Commit d8017a2

Browse files
committed
Merge pull request #273 from angular-ui/perf_choices_active_disabled
feat(choices): prevent calling $select.isActive/isDisabled when dropdown...
2 parents a73be72 + 7e8e589 commit d8017a2

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/select.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,13 @@
304304
};
305305

306306
ctrl.isActive = function(itemScope) {
307-
return ctrl.items.indexOf(itemScope[ctrl.itemProperty]) === ctrl.activeIndex;
307+
return ctrl.open && ctrl.items.indexOf(itemScope[ctrl.itemProperty]) === ctrl.activeIndex;
308308
};
309309

310310
ctrl.isDisabled = function(itemScope) {
311+
312+
if (!ctrl.open) return;
313+
311314
var itemIndex = ctrl.items.indexOf(itemScope[ctrl.itemProperty]);
312315
var isDisabled = false;
313316
var item;

test/select.spec.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ describe('ui-select tests', function() {
8585
}
8686

8787
function clickItem(el, text) {
88+
89+
if (!isDropdownOpened(el)){
90+
openDropdown(el);
91+
}
92+
8893
$(el).find('.ui-select-choices-row div:contains("' + text + '")').click();
8994
scope.$digest();
9095
}
@@ -114,6 +119,13 @@ describe('ui-select tests', function() {
114119
$timeout.flush();
115120
}
116121

122+
function openDropdown(el) {
123+
var $select = el.scope().$select;
124+
$select.open = true;
125+
scope.$digest();
126+
};
127+
128+
117129
// Tests
118130

119131
it('should compile child directives', function() {
@@ -357,6 +369,8 @@ describe('ui-select tests', function() {
357369
var option = $(this.el).find('.ui-select-choices-row div:contains("Wladimir")');
358370
var container = option.closest('.ui-select-choices-row');
359371

372+
openDropdown(this.el);
373+
360374
expect(container.hasClass('disabled')).toBeTruthy();
361375
});
362376
});
@@ -386,6 +400,8 @@ describe('ui-select tests', function() {
386400
var option = $(this.el).find('.ui-select-choices-row div:contains("Wladimir")');
387401
var container = option.closest('.ui-select-choices-row');
388402

403+
openDropdown(this.el);
404+
389405
expect(container.hasClass('disabled')).toBeTruthy();
390406
});
391407
});
@@ -415,6 +431,8 @@ describe('ui-select tests', function() {
415431
var option = $(this.el).find('.ui-select-choices-row div:contains("Wladimir")');
416432
var container = option.closest('.ui-select-choices-row');
417433

434+
openDropdown(this.el);
435+
418436
expect(container.hasClass('disabled')).toBeTruthy();
419437
});
420438
});
@@ -467,6 +485,9 @@ describe('ui-select tests', function() {
467485
el.scope().$select.search = 't';
468486
scope.$digest();
469487
var choices = el.find('.ui-select-choices-row');
488+
489+
openDropdown(el);
490+
470491
expect(choices.eq(0)).toHaveClass('active');
471492
expect(getGroupLabel(choices.eq(0)).text()).toBe('Foo');
472493

0 commit comments

Comments
 (0)