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

1 Answer 1

70

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

Sign up to request clarification or add additional context in comments.

4 Comments

Note that dropdown-menu-right is a CLASS, and NOT a directive or attribute (like many other dropdown settings are).
@cellepo, I believe I made that clear in the first three words of my answer.
@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...
Thank you, @BrunoRibeiro for the improvement suggestion. I picked up on it and added other frameworks as well. Happy coding!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.