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

Commit

Permalink
revert(dropdown): undo adding of open class on body
Browse files Browse the repository at this point in the history
This reverts commit bf63cef.
  • Loading branch information
wesleycho committed Oct 3, 2015
1 parent 5bc0851 commit 6f9f1fc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 32 deletions.
12 changes: 4 additions & 8 deletions src/dropdown/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@ angular.module('ui.bootstrap.dropdown', ['ui.bootstrap.position'])
setIsOpen = angular.noop,
toggleInvoker = $attrs.onToggle ? $parse($attrs.onToggle) : angular.noop,
appendToBody = false,
keynavEnabled = false,
selectedOption = null,
body = $document.find('body');
keynavEnabled =false,
selectedOption = null;

this.init = function(element) {
self.$element = element;
Expand All @@ -94,8 +93,7 @@ angular.module('ui.bootstrap.dropdown', ['ui.bootstrap.position'])
keynavEnabled = angular.isDefined($attrs.uibKeyboardNav);

if (appendToBody && self.dropdownMenu) {
body.append(self.dropdownMenu);
body.addClass('dropdown');
$document.find('body').append(self.dropdownMenu);
element.on('$destroy', function handleDestroyEvent() {
self.dropdownMenu.remove();
});
Expand Down Expand Up @@ -186,9 +184,7 @@ angular.module('ui.bootstrap.dropdown', ['ui.bootstrap.position'])
self.dropdownMenu.css(css);
}

var openContainer = appendToBody ? body : self.$element;

$animate[isOpen ? 'addClass' : 'removeClass'](openContainer, openClass).then(function() {
$animate[isOpen ? 'addClass' : 'removeClass'](self.$element, openClass).then(function() {
if (angular.isDefined(isOpen) && isOpen !== wasOpen) {
toggleInvoker($scope, { open: !!isOpen });
}
Expand Down
29 changes: 5 additions & 24 deletions src/dropdown/test/dropdown.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,29 +225,11 @@ describe('dropdownToggle', function() {
expect($document.find('#dropdown-menu').parent()[0]).toBe($document.find('body')[0]);
});

it('adds the dropdown class to the body', function() {
expect($document.find('body').hasClass('dropdown')).toBe(true);
});

it('removes the menu when the dropdown is removed', function() {
element.remove();
$rootScope.$digest();
expect($document.find('#dropdown-menu').length).toEqual(0);
});

it('toggles the open class on body', function() {
var body = $document.find('body');

expect(body.hasClass('open')).toBe(false);

element.find('[uib-dropdown-toggle]').click();

expect(body.hasClass('open')).toBe(true);

element.find('[uib-dropdown-toggle]').click();

expect(body.hasClass('open')).toBe(false);
});
});

describe('integration with $location URL rewriting', function() {
Expand Down Expand Up @@ -455,12 +437,11 @@ describe('dropdownToggle', function() {
it('should work with dropdown-append-to-body', function() {
element = $compile('<li uib-dropdown dropdown-append-to-body auto-close="outsideClick"><a href uib-dropdown-toggle></a><ul class="uib-dropdown-menu" id="dropdown-menu"><li><a href>Hello On Body</a></li></ul></li>')($rootScope);
clickDropdownToggle();
var body = $document.find('body');
expect(body.hasClass(dropdownConfig.openClass)).toBe(true);
expect(element.hasClass(dropdownConfig.openClass)).toBe(true);
$document.find('#dropdown-menu').find('li').eq(0).trigger('click');
expect(body.hasClass(dropdownConfig.openClass)).toBe(true);
expect(element.hasClass(dropdownConfig.openClass)).toBe(true);
$document.click();
expect(body.hasClass(dropdownConfig.openClass)).toBe(false);
expect(element.hasClass(dropdownConfig.openClass)).toBe(false);
});
});

Expand Down Expand Up @@ -686,7 +667,7 @@ describe('dropdownToggle', function() {

triggerKeyDown(element, 40);

expect($document.find('body').hasClass(dropdownConfig.openClass)).toBe(true);
expect(element.hasClass(dropdownConfig.openClass)).toBe(true);
var focusEl = $document.find('ul').eq(0).find('a');
expect(isFocused(focusEl)).toBe(true);
});
Expand All @@ -696,7 +677,7 @@ describe('dropdownToggle', function() {
triggerKeyDown(element, 40);
triggerKeyDown(element, 40);

expect($document.find('body').hasClass(dropdownConfig.openClass)).toBe(true);
expect(element.hasClass(dropdownConfig.openClass)).toBe(true);
var elem1 = $document.find('ul');
var elem2 = elem1.find('a');
var focusEl = $document.find('ul').eq(0).find('a').eq(1);
Expand Down

0 comments on commit 6f9f1fc

Please sign in to comment.