Skip to content

Commit

Permalink
Fixed #3254
Browse files Browse the repository at this point in the history
  • Loading branch information
Çağatay Çivici committed Jun 29, 2017
1 parent b46f36c commit bd83ad0
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions src/app/components/multiselect/multiselect.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {NgModule,Component,ElementRef,OnInit,AfterViewInit,AfterViewChecked,DoCheck,OnDestroy,Input,Output,Renderer2,EventEmitter,IterableDiffers,forwardRef,ViewChild,private cd: ChangeDetectorRef} from '@angular/core';
import {NgModule,Component,ElementRef,OnInit,AfterViewInit,AfterViewChecked,DoCheck,OnDestroy,Input,Output,Renderer2,EventEmitter,IterableDiffers,forwardRef,ViewChild,ChangeDetectorRef} from '@angular/core';
import {CommonModule} from '@angular/common';
import {SelectItem} from '../common/selectitem';
import {DomHandler} from '../dom/domhandler';
Expand Down Expand Up @@ -142,16 +142,6 @@ export class MultiSelect implements OnInit,AfterViewInit,AfterViewChecked,DoChec

ngOnInit() {
this.updateLabel();

this.documentClickListener = this.renderer.listen('document', 'click', () => {
if(!this.selfClick && !this.panelClick && this.overlayVisible) {
this.hide();
}

this.selfClick = false;
this.panelClick = false;
this.cd.markForCheck();
});
}

ngAfterViewInit() {
Expand Down Expand Up @@ -266,6 +256,7 @@ export class MultiSelect implements OnInit,AfterViewInit,AfterViewChecked,DoChec
show() {
this.overlayVisible = true;
this.panel.style.zIndex = String(++DomHandler.zindex);
this.bindDocumentClickListener();

if(this.appendTo)
this.domHandler.absolutePosition(this.panel, this.container);
Expand All @@ -277,6 +268,7 @@ export class MultiSelect implements OnInit,AfterViewInit,AfterViewChecked,DoChec

hide() {
this.overlayVisible = false;
this.unbindDocumentClickListener();
}

close(event) {
Expand Down Expand Up @@ -389,11 +381,30 @@ export class MultiSelect implements OnInit,AfterViewInit,AfterViewChecked,DoChec
return this.options;
}
}

ngOnDestroy() {

bindDocumentClickListener() {
if(!this.documentClickListener) {
this.documentClickListener = this.renderer.listen('document', 'click', () => {
if(!this.selfClick && !this.panelClick && this.overlayVisible) {
this.hide();
}

this.selfClick = false;
this.panelClick = false;
this.cd.markForCheck();
});
}
}

unbindDocumentClickListener() {
if(this.documentClickListener) {
this.documentClickListener();
}
this.documentClickListener = null;
}
}

ngOnDestroy() {
this.unbindDocumentClickListener();

if(this.appendTo) {
this.container.appendChild(this.panel);
Expand Down

0 comments on commit bd83ad0

Please sign in to comment.