From 6f9f1fcf6b70406f47d5e5d5642002fa6797d20a Mon Sep 17 00:00:00 2001 From: Wesley Cho Date: Fri, 2 Oct 2015 22:43:31 -0700 Subject: [PATCH] revert(dropdown): undo adding of `open` class on body This reverts commit bf63cef0aa605718013e11628f0f112f0473bc3d. --- src/dropdown/dropdown.js | 12 ++++-------- src/dropdown/test/dropdown.spec.js | 29 +++++------------------------ 2 files changed, 9 insertions(+), 32 deletions(-) diff --git a/src/dropdown/dropdown.js b/src/dropdown/dropdown.js index 6f39ae3dee..96702a402b 100644 --- a/src/dropdown/dropdown.js +++ b/src/dropdown/dropdown.js @@ -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; @@ -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(); }); @@ -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 }); } diff --git a/src/dropdown/test/dropdown.spec.js b/src/dropdown/test/dropdown.spec.js index 68375f06ca..c0c9d07c22 100644 --- a/src/dropdown/test/dropdown.spec.js +++ b/src/dropdown/test/dropdown.spec.js @@ -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() { @@ -455,12 +437,11 @@ describe('dropdownToggle', function() { it('should work with dropdown-append-to-body', function() { element = $compile('
  • ')($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); }); }); @@ -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); }); @@ -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);