Skip to content

Commit bfdaa24

Browse files
author
Erin Altenhof-Long
committed
revert(select): avoid checking option element selected properties in render
This reverts commit dc149de. That commit fixes a bug caused by Firefox updating `select.value` on hover. However, it causes other bugs with select including the issue described in angular#7715. This issue details how selects with a blank disabled option skip to the second option. We filed a bug with Firefox for the problematic behavior the reverted commit addresses https://bugzilla.mozilla.org/show_bug.cgi?id=1039047, and alternate Angular fixes are being investigated. Closes angular#7715 angular#7855
1 parent 9025113 commit bfdaa24

File tree

2 files changed

+1
-28
lines changed

2 files changed

+1
-28
lines changed

src/ng/directive/select.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -405,12 +405,6 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
405405
value = valueFn(scope, locals);
406406
}
407407
}
408-
// Update the null option's selected property here so $render cleans it up correctly
409-
if (optionGroupsCache[0].length > 1) {
410-
if (optionGroupsCache[0][1].id !== key) {
411-
optionGroupsCache[0][1].selected = false;
412-
}
413-
}
414408
}
415409
ctrl.$setViewValue(value);
416410
});
@@ -548,7 +542,7 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
548542
lastElement.val(existingOption.id = option.id);
549543
}
550544
// lastElement.prop('selected') provided by jQuery has side-effects
551-
if (existingOption.selected !== option.selected) {
545+
if (lastElement[0].selected !== option.selected) {
552546
lastElement.prop('selected', (existingOption.selected = option.selected));
553547
if (msie) {
554548
// See #7692

test/ng/directive/selectSpec.js

-21
Original file line numberDiff line numberDiff line change
@@ -733,27 +733,6 @@ describe('select', function() {
733733
expect(sortedHtml(options[2])).toEqual('<option value="1">3</option>');
734734
});
735735

736-
it('should not update selected property of an option element on digest with no change event',
737-
function() {
738-
createSingleSelect();
739-
740-
scope.$apply(function() {
741-
scope.values = [{name: 'A'}, {name: 'B'}, {name: 'C'}];
742-
scope.selected = scope.values[0];
743-
});
744-
745-
var options = element.find('option');
746-
var optionToSelect = options.eq(1);
747-
748-
expect(optionToSelect.text()).toBe('B');
749-
750-
optionToSelect.prop('selected', true);
751-
scope.$digest();
752-
753-
expect(optionToSelect.prop('selected')).toBe(true);
754-
expect(scope.selected).toBe(scope.values[0]);
755-
});
756-
757736
describe('binding', function() {
758737

759738
it('should bind to scope value', function() {

0 commit comments

Comments
 (0)