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

Commit 0495ff0

Browse files
committed
feat(dropdown): add open class support
- Adds support for the `uib-dropdown-open` class to be toggled on the container element of a dropdown menu on dropdown toggle Closes #4466 Closes #4794
1 parent b77618e commit 0495ff0

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/dropdown/dropdown.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
angular.module('ui.bootstrap.dropdown', ['ui.bootstrap.position'])
22

33
.constant('uibDropdownConfig', {
4+
appendToOpenClass: 'uib-dropdown-open',
45
openClass: 'open'
56
})
67

@@ -69,6 +70,7 @@ angular.module('ui.bootstrap.dropdown', ['ui.bootstrap.position'])
6970
var self = this,
7071
scope = $scope.$new(), // create a child scope so we are not polluting original one
7172
templateScope,
73+
appendToOpenClass = dropdownConfig.appendToOpenClass,
7274
openClass = dropdownConfig.openClass,
7375
getIsOpen,
7476
setIsOpen = angular.noop,
@@ -216,7 +218,7 @@ angular.module('ui.bootstrap.dropdown', ['ui.bootstrap.position'])
216218

217219
var openContainer = appendTo ? appendTo : $element;
218220

219-
$animate[isOpen ? 'addClass' : 'removeClass'](openContainer, openClass).then(function() {
221+
$animate[isOpen ? 'addClass' : 'removeClass'](openContainer, appendTo ? appendToOpenClass : openClass).then(function() {
220222
if (angular.isDefined(isOpen) && isOpen !== wasOpen) {
221223
toggleInvoker($scope, { open: !!isOpen });
222224
}

src/dropdown/test/dropdown.spec.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -261,11 +261,11 @@ describe('dropdownToggle', function() {
261261
it('toggles open class on container', function() {
262262
var container = $document.find('#dropdown-container');
263263

264-
expect(container.hasClass('open')).toBe(false);
264+
expect(container.hasClass('uib-dropdown-open')).toBe(false);
265265
element.find('[uib-dropdown-toggle]').click();
266-
expect(container.hasClass('open')).toBe(true);
266+
expect(container.hasClass('uib-dropdown-open')).toBe(true);
267267
element.find('[uib-dropdown-toggle]').click();
268-
expect(container.hasClass('open')).toBe(false);
268+
expect(container.hasClass('uib-dropdown-open')).toBe(false);
269269
});
270270

271271
it('removes the menu when the dropdown is removed', function() {
@@ -481,11 +481,11 @@ describe('dropdownToggle', function() {
481481
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);
482482
clickDropdownToggle();
483483
var dropdownMenu = $document.find('#dropdown-menu');
484-
expect(dropdownMenu.parent().hasClass(dropdownConfig.openClass)).toBe(true);
484+
expect(dropdownMenu.parent().hasClass(dropdownConfig.appendToOpenClass)).toBe(true);
485485
dropdownMenu.find('li').eq(0).trigger('click');
486-
expect(dropdownMenu.parent().hasClass(dropdownConfig.openClass)).toBe(true);
486+
expect(dropdownMenu.parent().hasClass(dropdownConfig.appendToOpenClass)).toBe(true);
487487
$document.click();
488-
expect(dropdownMenu.parent().hasClass(dropdownConfig.openClass)).toBe(false);
488+
expect(dropdownMenu.parent().hasClass(dropdownConfig.appendToOpenClass)).toBe(false);
489489
});
490490
});
491491

@@ -713,7 +713,7 @@ describe('dropdownToggle', function() {
713713

714714
var dropdownMenu = $document.find('#dropdown-menu');
715715

716-
expect(dropdownMenu.parent().hasClass(dropdownConfig.openClass)).toBe(true);
716+
expect(dropdownMenu.parent().hasClass(dropdownConfig.appendToOpenClass)).toBe(true);
717717
var focusEl = $document.find('ul').eq(0).find('a');
718718
expect(isFocused(focusEl)).toBe(true);
719719
});
@@ -725,7 +725,7 @@ describe('dropdownToggle', function() {
725725

726726
var dropdownMenu = $document.find('#dropdown-menu');
727727

728-
expect(dropdownMenu.parent().hasClass(dropdownConfig.openClass)).toBe(true);
728+
expect(dropdownMenu.parent().hasClass(dropdownConfig.appendToOpenClass)).toBe(true);
729729
var elem1 = $document.find('ul');
730730
var elem2 = elem1.find('a');
731731
var focusEl = $document.find('ul').eq(0).find('a').eq(1);

0 commit comments

Comments
 (0)