Skip to content

Commit 56b8dc5

Browse files
jnizeticfantv
authored andcommitted
feat(dropdown): add support for dropup
also improves the demo to show how to align the dropdown menu to the right Closes #667
1 parent eccf859 commit 56b8dc5

File tree

3 files changed

+38
-8
lines changed

3 files changed

+38
-8
lines changed
Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
1-
<div ngbDropdown>
2-
<button class="btn btn-outline-primary" id="dropdownMenu1" ngbDropdownToggle>Toggle dropdown</button>
3-
<div class="dropdown-menu" aria-labelledby="dropdownMenu1">
4-
<button class="dropdown-item">Action - 1</button>
5-
<button class="dropdown-item">Another Action</button>
6-
<button class="dropdown-item">Something else is here</button>
1+
<div class="row">
2+
<div class="col-xs-6">
3+
<div ngbDropdown class="d-inline-block">
4+
<button class="btn btn-outline-primary" id="dropdownMenu1" ngbDropdownToggle>Toggle dropdown</button>
5+
<div class="dropdown-menu" aria-labelledby="dropdownMenu1">
6+
<button class="dropdown-item">Action - 1</button>
7+
<button class="dropdown-item">Another Action</button>
8+
<button class="dropdown-item">Something else is here</button>
9+
</div>
10+
</div>
11+
</div>
12+
13+
<div class="col-xs-6 text-xs-right">
14+
<div ngbDropdown [up]="true" class="d-inline-block">
15+
<button class="btn btn-outline-primary" id="dropdownMenu2" ngbDropdownToggle>Toggle dropup</button>
16+
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenu2">
17+
<button class="dropdown-item">Action - 1</button>
18+
<button class="dropdown-item">Another Action</button>
19+
<button class="dropdown-item">Something else is here</button>
20+
</div>
21+
</div>
722
</div>
823
</div>

src/dropdown/dropdown.spec.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function getDropdownEl(tc) {
1717
describe('ngb-dropdown', () => {
1818
beforeEach(() => { TestBed.configureTestingModule({declarations: [TestComponent], imports: [NgbDropdownModule]}); });
1919

20-
it('should be closed by default', () => {
20+
it('should be closed and down by default', () => {
2121
const html = `<div ngbDropdown></div>`;
2222

2323
const fixture = createTestComponent(html);
@@ -27,6 +27,15 @@ describe('ngb-dropdown', () => {
2727
expect(getDropdownEl(compiled)).not.toHaveCssClass('open');
2828
});
2929

30+
it('should be up if up input is true', () => {
31+
const html = `<div ngbDropdown [up]="true"></div>`;
32+
33+
const fixture = createTestComponent(html);
34+
const compiled = fixture.nativeElement;
35+
36+
expect(getDropdownEl(compiled)).toHaveCssClass('dropup');
37+
});
38+
3039
it('should be open initially if open expression is true', () => {
3140
const html = `<div ngbDropdown [open]="true"></div>`;
3241

src/dropdown/dropdown.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,19 @@ import {Directive, Input, Output, HostListener, EventEmitter} from '@angular/cor
77
selector: '[ngbDropdown]',
88
exportAs: 'ngbDropdown',
99
host: {
10-
'class': 'dropdown',
10+
'[class.dropdown]': '!up',
11+
'[class.dropup]': 'up',
1112
'[class.open]': 'isOpen()',
1213
'(keyup.esc)': 'closeFromOutside()',
1314
'(document:click)': 'closeFromOutside()'
1415
}
1516
})
1617
export class NgbDropdown {
18+
/**
19+
* Indicates that the dropdown should open upwards
20+
*/
21+
@Input() up = false;
22+
1723
/**
1824
* Indicates that dropdown should be closed when selecting one of dropdown items (click) or pressing ESC.
1925
*/

0 commit comments

Comments
 (0)