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

feat(dropdown): add open class support #4794

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/dropdown/dropdown.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
angular.module('ui.bootstrap.dropdown', ['ui.bootstrap.position'])

.constant('uibDropdownConfig', {
appendToOpenClass: 'uib-dropdown-open',
openClass: 'open'
})

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

var openContainer = appendTo ? appendTo : $element;

$animate[isOpen ? 'addClass' : 'removeClass'](openContainer, openClass).then(function() {
$animate[isOpen ? 'addClass' : 'removeClass'](openContainer, appendTo ? appendToOpenClass : openClass).then(function() {
if (angular.isDefined(isOpen) && isOpen !== wasOpen) {
toggleInvoker($scope, { open: !!isOpen });
}
Expand Down
16 changes: 8 additions & 8 deletions src/dropdown/test/dropdown.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,11 @@ describe('dropdownToggle', function() {
it('toggles open class on container', function() {
var container = $document.find('#dropdown-container');

expect(container.hasClass('open')).toBe(false);
expect(container.hasClass('uib-dropdown-open')).toBe(false);
element.find('[uib-dropdown-toggle]').click();
expect(container.hasClass('open')).toBe(true);
expect(container.hasClass('uib-dropdown-open')).toBe(true);
element.find('[uib-dropdown-toggle]').click();
expect(container.hasClass('open')).toBe(false);
expect(container.hasClass('uib-dropdown-open')).toBe(false);
});

it('removes the menu when the dropdown is removed', function() {
Expand Down Expand Up @@ -481,11 +481,11 @@ describe('dropdownToggle', 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 dropdownMenu = $document.find('#dropdown-menu');
expect(dropdownMenu.parent().hasClass(dropdownConfig.openClass)).toBe(true);
expect(dropdownMenu.parent().hasClass(dropdownConfig.appendToOpenClass)).toBe(true);
dropdownMenu.find('li').eq(0).trigger('click');
expect(dropdownMenu.parent().hasClass(dropdownConfig.openClass)).toBe(true);
expect(dropdownMenu.parent().hasClass(dropdownConfig.appendToOpenClass)).toBe(true);
$document.click();
expect(dropdownMenu.parent().hasClass(dropdownConfig.openClass)).toBe(false);
expect(dropdownMenu.parent().hasClass(dropdownConfig.appendToOpenClass)).toBe(false);
});
});

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

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

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

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

expect(dropdownMenu.parent().hasClass(dropdownConfig.openClass)).toBe(true);
expect(dropdownMenu.parent().hasClass(dropdownConfig.appendToOpenClass)).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