Skip to content

Commit

Permalink
fix(dropdown): add "dropdown" class for placements other than "top"
Browse files Browse the repository at this point in the history
Fixes #1847
Closes #1852
  • Loading branch information
mschoudry authored and pkozlowski-opensource committed Sep 15, 2017
1 parent 95a007f commit ed88f72
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
15 changes: 15 additions & 0 deletions src/dropdown/dropdown.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@ describe('ngb-dropdown', () => {
expect(getDropdownEl(compiled)).toHaveCssClass('dropup');
});

it('should have dropdown CSS class if placement is other than top', () => {
const html = `
<div ngbDropdown placement="bottom">
<div ngbDropdownMenu>
<a class="dropdown-item">dropDown item</a>
<a class="dropdown-item">dropDown item</a>
</div>
</div>`;

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

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

it('should be open initially if open expression is true', () => {
const html = `
<div ngbDropdown [open]="true">
Expand Down
6 changes: 4 additions & 2 deletions src/dropdown/dropdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,16 @@ export class NgbDropdownMenu {
applyPlacement(_placement: Placement) {
// remove the current placement classes
this._renderer.removeClass(this._elementRef.nativeElement.parentElement, 'dropup');
this._renderer.removeClass(this._elementRef.nativeElement.parentElement, 'dropdown');
this.placement = _placement;
/**
* apply the new placement
* change the class only in case of top to show up arrow
* or use defualt which is dropdown to show down arrow
* in case of top use up-arrow or down-arrow otherwise
*/
if (_placement.search('^top') !== -1) {
this._renderer.addClass(this._elementRef.nativeElement.parentElement, 'dropup');
} else {
this._renderer.addClass(this._elementRef.nativeElement.parentElement, 'dropdown');
}
}
}
Expand Down

0 comments on commit ed88f72

Please sign in to comment.