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

Commit 2332f14

Browse files
schmuliwesleycho
authored andcommitted
fix(dropdown): align when using dropdown-menu-body
- Fixes the right alignment when using the `dropdown-menu-body` class in conjunction with the dropdown component Closes #3913 Fixes #3820
1 parent 14689e0 commit 2332f14

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/dropdown/dropdown.js

+17-7
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,23 @@ angular.module('ui.bootstrap.dropdown', ['ui.bootstrap.position'])
162162
};
163163

164164
scope.$watch('isOpen', function( isOpen, wasOpen ) {
165-
if ( appendToBody && self.dropdownMenu ) {
166-
var pos = $position.positionElements(self.$element, self.dropdownMenu, 'bottom-left', true);
167-
self.dropdownMenu.css({
168-
top: pos.top + 'px',
169-
left: pos.left + 'px',
170-
display: isOpen ? 'block' : 'none'
171-
});
165+
if (appendToBody && self.dropdownMenu) {
166+
var pos = $position.positionElements(self.$element, self.dropdownMenu, 'bottom-left', true);
167+
var css = {
168+
top: pos.top + 'px',
169+
display: isOpen ? 'block' : 'none'
170+
};
171+
172+
var rightalign = self.dropdownMenu.hasClass('dropdown-menu-right');
173+
if (!rightalign) {
174+
css.left = pos.left + 'px';
175+
css.right = 'auto';
176+
} else {
177+
css.left = 'auto';
178+
css.right = (window.innerWidth - (pos.left + self.$element.prop('offsetWidth'))) + 'px';
179+
}
180+
181+
self.dropdownMenu.css(css);
172182
}
173183

174184
$animate[isOpen ? 'addClass' : 'removeClass'](self.$element, openClass).then(function() {

0 commit comments

Comments
 (0)