Skip to content

Commit d6f6d25

Browse files
committed
feat(dropdown): now you can bind to dropup property
1 parent d287d64 commit d6f6d25

File tree

3 files changed

+26
-19
lines changed

3 files changed

+26
-19
lines changed
Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1-
<div class="btn-group dropup" dropdown dropup>
1+
<div class="btn-group" dropdown [dropup]="isDropup">
22
<button dropdownToggle type="button" class="btn btn-primary dropdown-toggle">
33
Dropup <span class="caret"></span>
44
</button>
5-
<ul *dropdownMenu class="dropdown-menu" role="menu">
6-
<li role="menuitem"><a class="dropdown-item" href="#">Action</a></li>
7-
<li role="menuitem"><a class="dropdown-item" href="#">Another action</a>
8-
</li>
9-
<li role="menuitem"><a class="dropdown-item" href="#">Something else
10-
here</a></li>
11-
<li class="divider dropdown-divider"></li>
12-
<li role="menuitem"><a class="dropdown-item" href="#">Separated link</a>
13-
</li>
14-
</ul>
5+
<ul *dropdownMenu class="dropdown-menu" role="menu">
6+
<li role="menuitem"><a class="dropdown-item" href="#">Action</a></li>
7+
<li role="menuitem"><a class="dropdown-item" href="#">Another action</a>
8+
</li>
9+
<li role="menuitem"><a class="dropdown-item" href="#">Something else
10+
here</a></li>
11+
<li class="divider dropdown-divider"></li>
12+
<li role="menuitem"><a class="dropdown-item" href="#">Separated link</a>
13+
</li>
14+
</ul>
1515
</div>
16+
<div class="checkbox"><label>
17+
<input type="checkbox" value="true" [(ngModel)]="isDropup"
18+
style="display: inline-block;"
19+
>{{ isDropup ? 'Is dropup' : 'Is dropdown' }}
20+
</label></div>

demo/src/app/components/+dropdown/demos/dropup/dropup.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ import { Component } from '@angular/core';
55
templateUrl: './dropup.html'
66
})
77
export class DemoDropupComponent {
8+
isDropup = true;
89
}

src/dropdown/bs-dropdown.directive.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import { BsDropdownState } from './bs-dropdown.state';
1212
@Directive({
1313
selector: '[bsDropdown],[dropdown]',
1414
exportAs: 'bs-dropdown',
15-
providers: [BsDropdownState]
15+
providers: [BsDropdownState],
16+
host: {'[class.dropup]': 'dropup'}
1617
})
1718
export class BsDropdownDirective implements OnInit, OnDestroy {
1819
/**
@@ -138,20 +139,20 @@ export class BsDropdownDirective implements OnInit, OnDestroy {
138139
this._state.dropdownMenu
139140
.then((dropdownMenu) => {
140141
// check direction in which dropdown should be opened
141-
this.dropup = typeof this.dropup !== 'undefined' || this.dropup;
142-
this._state.direction = this.dropup ? 'up' : 'down';
143-
if (!this.placement) {
144-
this.placement = this.dropup ? 'top left' : 'bottom left';
145-
}
142+
const _dropup = this.dropup === true ||
143+
(typeof this.dropup !== 'undefined' && this.dropup !== false);
144+
this._state.direction = _dropup ? 'up' : 'down';
145+
const _placement = this.placement ||
146+
(_dropup ? 'top left' : 'bottom left');
146147

147148
// show dropdown
148149
this._dropdown
149150
.attach(BsDropdownContainerComponent)
150151
.to(this.container)
151-
.position({attachment: this.placement})
152+
.position({attachment: _placement})
152153
.show({
153154
content: dropdownMenu,
154-
placement: this.placement
155+
placement: _placement
155156
});
156157

157158
this._state.isOpenChange.emit(true);

0 commit comments

Comments
 (0)