Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Commit

Permalink
fix(dropdown): Fix $digest:inprog on dismissal without using $timeout
Browse files Browse the repository at this point in the history
Signed-off-by: Max Fierke <[email protected]>
  • Loading branch information
maxfierke committed Mar 24, 2015
1 parent 44e7d55 commit 1cee95a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
10 changes: 7 additions & 3 deletions src/dropdown/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ angular.module('ui.bootstrap.dropdown', [])
openClass: 'open'
})

.service('dropdownService', ['$document', '$timeout', function($document, $timeout) {
.service('dropdownService', ['$document', function($document) {
var openScope = null;

this.open = function( dropdownScope ) {
Expand Down Expand Up @@ -38,9 +38,13 @@ angular.module('ui.bootstrap.dropdown', [])
return;
}

$timeout(function() {
if (!openScope.$$phase) {
openScope.$apply(function() {
openScope.isOpen = false;
});
} else {
openScope.isOpen = false;
});
}
};

var escapeKeyBind = function( evt ) {
Expand Down
16 changes: 2 additions & 14 deletions src/dropdown/test/dropdown.spec.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,23 @@
describe('dropdownToggle', function() {
var $compile, $rootScope, $document, $timeout, element;
var $compile, $rootScope, $document, element;

beforeEach(module('ui.bootstrap.dropdown'));

beforeEach(inject(function(_$compile_, _$rootScope_, _$document_, _$timeout_) {
beforeEach(inject(function(_$compile_, _$rootScope_, _$document_) {
$compile = _$compile_;
$rootScope = _$rootScope_;
$document = _$document_;
$timeout = _$timeout_;
}));

var processTimeout = function () {
try {
$timeout.flush();
} catch (e) {}
$rootScope.$digest();
};

var clickDropdownToggle = function(elm) {
elm = elm || element;
elm.find('a[dropdown-toggle]').click();
processTimeout();
};

var triggerKeyDown = function (element, keyCode) {
var e = $.Event('keydown');
e.which = keyCode;
element.trigger(e);
processTimeout();
};

var isFocused = function(elm) {
Expand Down Expand Up @@ -59,7 +49,6 @@ describe('dropdownToggle', function() {

var optionEl = element.find('ul > li').eq(0).find('a').eq(0);
optionEl.click();
processTimeout();
expect(element.hasClass('open')).toBe(false);
element.remove();
});
Expand All @@ -68,7 +57,6 @@ describe('dropdownToggle', function() {
clickDropdownToggle();
expect(element.hasClass('open')).toBe(true);
$document.click();
processTimeout();
expect(element.hasClass('open')).toBe(false);
});

Expand Down

0 comments on commit 1cee95a

Please sign in to comment.