25

I have used angular bootstrap dropdown successfully link. But the problem it that the dropdown opens on the right side. How can i make it to open on left? Here is the markup and js i used from the given link.

Markup:

<div ng-controller="DropdownCtrl">
<!-- Single button with keyboard nav -->
<div class="btn-group" uib-dropdown keyboard-nav>
    <button id="simple-btn-keyboard-nav" type="button" class="btn btn-primary" uib-dropdown-toggle>
        Dropdown with keyboard navigation <span class="caret"></span>
    </button>
    <ul uib-dropdown-menu role="menu" aria-labelledby="simple-btn-keyboard-nav">
        <li role="menuitem"><a href="#">Action</a></li>
        <li role="menuitem"><a href="#">Another action</a></li>
        <li role="menuitem"><a href="#">Something else here</a></li>
        <li class="divider"></li>
        <li role="menuitem"><a href="#">Separated link</a></li>
    </ul>
</div>
</div>

js:

angular.module('ui.bootstrap.demo').controller('DropdownCtrl', function ($scope, $log) {
$scope.items = [
'The first choice!',
'And another choice for you.',
'but wait! A third!'
];

$scope.status = {
isopen: false
};

$scope.toggled = function(open) {
$log.log('Dropdown is now: ', open);
};

$scope.toggleDropdown = function($event) {
$event.preventDefault();
$event.stopPropagation();
$scope.status.isopen = !$scope.status.isopen;
};

$scope.appendToEl = angular.element(document.querySelector('#dropdown-long-content'));
});

please help

Gaurav Gupta
  • 1,929
  • 4
  • 21
  • 40

1 Answers1

69

Add the class dropdown-menu-right to your <ul uib-dropdown-menu>.

By default, the drowpdown opens aligned to the left side of the parent and growing towards right side. When added the class dropdown-menu-right it will open aligned on the right side.

EDIT:
Angular Bootstrap with Bootstrap 4 allows a more fine-tuned placement of the dropdown, using the placement attribute (w/ possible choices of bottom-right, right or top-right).
Source: https://ng-bootstrap.github.io/#/components/dropdown/api

Vue-Bootstrap provides the right attribute (boolean).
Source: https://bootstrap-vue.js.org/docs/components/dropdown/#bd-content

React-bootstrap calls the attribute pullRight (boolean)
Source: https://react-bootstrap.github.io/components/dropdowns/#btn-dropdowns-right

tao
  • 82,996
  • 16
  • 114
  • 150
  • 3
    Note that dropdown-menu-right is a CLASS, and NOT a directive or attribute (like many other dropdown settings are). – cellepo Mar 03 '18 at 00:16
  • @cellepo, I believe I made that clear in the first three words of my answer. – tao Mar 03 '18 at 00:21
  • @Andrei_Gheorghiu I was just emphasizing that fact, not correcting you (I even upvoted your Answer; thank you for it). Don't take it so personally. Your ul also doesn't actually have a class... – cellepo Mar 03 '18 at 00:31
  • Thank you, @BrunoRibeiro for the improvement suggestion. I picked up on it and added other frameworks as well. Happy coding! – tao Oct 29 '18 at 14:41