From a7a02ff1fe3dcdf9af21086ad95965d425d086b9 Mon Sep 17 00:00:00 2001 From: mkjeff Date: Mon, 14 Mar 2016 14:05:12 +0800 Subject: [PATCH] fix(dropdowns): dropdown should close correctly when used in modals (fixes #267, fixes #221) --- components/dropdown/dropdown.directive.ts | 1 + components/dropdown/dropdown.service.ts | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/components/dropdown/dropdown.directive.ts b/components/dropdown/dropdown.directive.ts index 3997c43246..8a8e9fff67 100644 --- a/components/dropdown/dropdown.directive.ts +++ b/components/dropdown/dropdown.directive.ts @@ -23,6 +23,7 @@ export class Dropdown implements OnInit, OnDestroy { @Output() public isOpenChange:EventEmitter = new EventEmitter(); @HostBinding('class.dropdown') private addClass = true; + private _isOpen:boolean; // index of selected element public selectedOption:number; diff --git a/components/dropdown/dropdown.service.ts b/components/dropdown/dropdown.service.ts index dea10952b2..133580a4a4 100644 --- a/components/dropdown/dropdown.service.ts +++ b/components/dropdown/dropdown.service.ts @@ -7,18 +7,17 @@ import {Dropdown} from './dropdown.directive'; export class DropdownService { private openScope:Dropdown; - private dropdownScope:Dropdown; private closeDropdownBind:EventListener = this.closeDropdown.bind(this); private keybindFilterBind:EventListener = this.keybindFilter.bind(this); public open(dropdownScope:Dropdown) { if (!this.openScope) { - window.document.addEventListener('click', this.closeDropdownBind); + window.document.addEventListener('click', this.closeDropdownBind, true); window.document.addEventListener('keydown', this.keybindFilterBind); } - if (this.openScope && this.openScope !== this.dropdownScope) { + if (this.openScope && this.openScope !== dropdownScope) { this.openScope.isOpen = false; } @@ -31,7 +30,7 @@ export class DropdownService { } this.openScope = null; - window.document.removeEventListener('click', this.closeDropdownBind); + window.document.removeEventListener('click', this.closeDropdownBind, true); window.document.removeEventListener('keydown', this.keybindFilterBind); }