Skip to content

Commit

Permalink
feat(dropdown): add support for dropup
Browse files Browse the repository at this point in the history
also improves the demo to show how to align the dropdown menu to the right

Closes #667
  • Loading branch information
jnizet authored and icfantv committed Sep 2, 2016
1 parent eccf859 commit 56b8dc5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
27 changes: 21 additions & 6 deletions demo/src/app/components/dropdown/demos/basic/dropdown-basic.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
<div ngbDropdown>
<button class="btn btn-outline-primary" id="dropdownMenu1" ngbDropdownToggle>Toggle dropdown</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenu1">
<button class="dropdown-item">Action - 1</button>
<button class="dropdown-item">Another Action</button>
<button class="dropdown-item">Something else is here</button>
<div class="row">
<div class="col-xs-6">
<div ngbDropdown class="d-inline-block">
<button class="btn btn-outline-primary" id="dropdownMenu1" ngbDropdownToggle>Toggle dropdown</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenu1">
<button class="dropdown-item">Action - 1</button>
<button class="dropdown-item">Another Action</button>
<button class="dropdown-item">Something else is here</button>
</div>
</div>
</div>

<div class="col-xs-6 text-xs-right">
<div ngbDropdown [up]="true" class="d-inline-block">
<button class="btn btn-outline-primary" id="dropdownMenu2" ngbDropdownToggle>Toggle dropup</button>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenu2">
<button class="dropdown-item">Action - 1</button>
<button class="dropdown-item">Another Action</button>
<button class="dropdown-item">Something else is here</button>
</div>
</div>
</div>
</div>
11 changes: 10 additions & 1 deletion src/dropdown/dropdown.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function getDropdownEl(tc) {
describe('ngb-dropdown', () => {
beforeEach(() => { TestBed.configureTestingModule({declarations: [TestComponent], imports: [NgbDropdownModule]}); });

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

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

it('should be up if up input is true', () => {
const html = `<div ngbDropdown [up]="true"></div>`;

const fixture = createTestComponent(html);
const compiled = fixture.nativeElement;

expect(getDropdownEl(compiled)).toHaveCssClass('dropup');
});

it('should be open initially if open expression is true', () => {
const html = `<div ngbDropdown [open]="true"></div>`;

Expand Down
8 changes: 7 additions & 1 deletion src/dropdown/dropdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@ import {Directive, Input, Output, HostListener, EventEmitter} from '@angular/cor
selector: '[ngbDropdown]',
exportAs: 'ngbDropdown',
host: {
'class': 'dropdown',
'[class.dropdown]': '!up',
'[class.dropup]': 'up',
'[class.open]': 'isOpen()',
'(keyup.esc)': 'closeFromOutside()',
'(document:click)': 'closeFromOutside()'
}
})
export class NgbDropdown {
/**
* Indicates that the dropdown should open upwards
*/
@Input() up = false;

/**
* Indicates that dropdown should be closed when selecting one of dropdown items (click) or pressing ESC.
*/
Expand Down

0 comments on commit 56b8dc5

Please sign in to comment.