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

Commit

Permalink
fix(dropdown): align when using dropdown-menu-body
Browse files Browse the repository at this point in the history
- Fixes the right alignment when using the `dropdown-menu-body` class in
  conjunction with the dropdown component

Closes #3913
Fixes #3820
  • Loading branch information
schmuli authored and wesleycho committed Jul 20, 2015
1 parent 14689e0 commit 2332f14
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/dropdown/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,23 @@ angular.module('ui.bootstrap.dropdown', ['ui.bootstrap.position'])
};

scope.$watch('isOpen', function( isOpen, wasOpen ) {
if ( appendToBody && self.dropdownMenu ) {
var pos = $position.positionElements(self.$element, self.dropdownMenu, 'bottom-left', true);
self.dropdownMenu.css({
top: pos.top + 'px',
left: pos.left + 'px',
display: isOpen ? 'block' : 'none'
});
if (appendToBody && self.dropdownMenu) {
var pos = $position.positionElements(self.$element, self.dropdownMenu, 'bottom-left', true);
var css = {
top: pos.top + 'px',
display: isOpen ? 'block' : 'none'
};

var rightalign = self.dropdownMenu.hasClass('dropdown-menu-right');
if (!rightalign) {
css.left = pos.left + 'px';
css.right = 'auto';
} else {
css.left = 'auto';
css.right = (window.innerWidth - (pos.left + self.$element.prop('offsetWidth'))) + 'px';
}

self.dropdownMenu.css(css);
}

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

0 comments on commit 2332f14

Please sign in to comment.