From d6f6d2544ac4bfbb4e895033190953b27c7f0274 Mon Sep 17 00:00:00 2001 From: Dmitriy Schekhovtsov Date: Thu, 30 Mar 2017 20:02:39 +0300 Subject: [PATCH] feat(dropdown): now you can bind to dropup property --- .../+dropdown/demos/dropup/dropup.html | 27 +++++++++++-------- .../+dropdown/demos/dropup/dropup.ts | 1 + src/dropdown/bs-dropdown.directive.ts | 17 ++++++------ 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/demo/src/app/components/+dropdown/demos/dropup/dropup.html b/demo/src/app/components/+dropdown/demos/dropup/dropup.html index d135eb6c0f..8cd6b17d3a 100644 --- a/demo/src/app/components/+dropdown/demos/dropup/dropup.html +++ b/demo/src/app/components/+dropdown/demos/dropup/dropup.html @@ -1,15 +1,20 @@ -
+ +
diff --git a/demo/src/app/components/+dropdown/demos/dropup/dropup.ts b/demo/src/app/components/+dropdown/demos/dropup/dropup.ts index 49cc2d375f..79e237f283 100644 --- a/demo/src/app/components/+dropdown/demos/dropup/dropup.ts +++ b/demo/src/app/components/+dropdown/demos/dropup/dropup.ts @@ -5,4 +5,5 @@ import { Component } from '@angular/core'; templateUrl: './dropup.html' }) export class DemoDropupComponent { + isDropup = true; } diff --git a/src/dropdown/bs-dropdown.directive.ts b/src/dropdown/bs-dropdown.directive.ts index 816576e440..bca391370c 100644 --- a/src/dropdown/bs-dropdown.directive.ts +++ b/src/dropdown/bs-dropdown.directive.ts @@ -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 { /** @@ -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);