Skip to content

Commit

Permalink
feat(dropdown): now you can bind to dropup property
Browse files Browse the repository at this point in the history
  • Loading branch information
valorkin committed Mar 30, 2017
1 parent d287d64 commit d6f6d25
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
27 changes: 16 additions & 11 deletions demo/src/app/components/+dropdown/demos/dropup/dropup.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
<div class="btn-group dropup" dropdown dropup>
<div class="btn-group" dropdown [dropup]="isDropup">
<button dropdownToggle type="button" class="btn btn-primary dropdown-toggle">
Dropup <span class="caret"></span>
</button>
<ul *dropdownMenu class="dropdown-menu" role="menu">
<li role="menuitem"><a class="dropdown-item" href="#">Action</a></li>
<li role="menuitem"><a class="dropdown-item" href="#">Another action</a>
</li>
<li role="menuitem"><a class="dropdown-item" href="#">Something else
here</a></li>
<li class="divider dropdown-divider"></li>
<li role="menuitem"><a class="dropdown-item" href="#">Separated link</a>
</li>
</ul>
<ul *dropdownMenu class="dropdown-menu" role="menu">
<li role="menuitem"><a class="dropdown-item" href="#">Action</a></li>
<li role="menuitem"><a class="dropdown-item" href="#">Another action</a>
</li>
<li role="menuitem"><a class="dropdown-item" href="#">Something else
here</a></li>
<li class="divider dropdown-divider"></li>
<li role="menuitem"><a class="dropdown-item" href="#">Separated link</a>
</li>
</ul>
</div>
<div class="checkbox"><label>
<input type="checkbox" value="true" [(ngModel)]="isDropup"
style="display: inline-block;"
>{{ isDropup ? 'Is dropup' : 'Is dropdown' }}
</label></div>
1 change: 1 addition & 0 deletions demo/src/app/components/+dropdown/demos/dropup/dropup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ import { Component } from '@angular/core';
templateUrl: './dropup.html'
})
export class DemoDropupComponent {
isDropup = true;
}
17 changes: 9 additions & 8 deletions src/dropdown/bs-dropdown.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import { BsDropdownState } from './bs-dropdown.state';
@Directive({
selector: '[bsDropdown],[dropdown]',
exportAs: 'bs-dropdown',
providers: [BsDropdownState]
providers: [BsDropdownState],
host: {'[class.dropup]': 'dropup'}
})
export class BsDropdownDirective implements OnInit, OnDestroy {
/**
Expand Down Expand Up @@ -138,20 +139,20 @@ export class BsDropdownDirective implements OnInit, OnDestroy {
this._state.dropdownMenu
.then((dropdownMenu) => {
// check direction in which dropdown should be opened
this.dropup = typeof this.dropup !== 'undefined' || this.dropup;
this._state.direction = this.dropup ? 'up' : 'down';
if (!this.placement) {
this.placement = this.dropup ? 'top left' : 'bottom left';
}
const _dropup = this.dropup === true ||
(typeof this.dropup !== 'undefined' && this.dropup !== false);
this._state.direction = _dropup ? 'up' : 'down';
const _placement = this.placement ||
(_dropup ? 'top left' : 'bottom left');

// show dropdown
this._dropdown
.attach(BsDropdownContainerComponent)
.to(this.container)
.position({attachment: this.placement})
.position({attachment: _placement})
.show({
content: dropdownMenu,
placement: this.placement
placement: _placement
});

this._state.isOpenChange.emit(true);
Expand Down

0 comments on commit d6f6d25

Please sign in to comment.