Commit a88509d3 authored by Edward Carroll's avatar Edward Carroll Committed by Massimo Costa
Browse files

fix(popup): Made document click handler only apply when popup is open (#229)

Closes #194
parent b12b4092
......@@ -102,12 +102,12 @@ export class SuiDatepickerDirective
@Output("pickerValidatorChange")
public onValidatorChange:EventEmitter<void>;
constructor(element:ElementRef,
public renderer:Renderer2,
constructor(public renderer:Renderer2,
element:ElementRef,
componentFactory:SuiComponentFactory,
public localizationService:SuiLocalizationService) {
super(element, componentFactory, SuiDatepicker, new PopupConfig({
super(renderer, element, componentFactory, SuiDatepicker, new PopupConfig({
trigger: PopupTrigger.Focus,
placement: PositioningPlacement.BottomLeft,
transition: "scale",
......
import { ComponentRef, ElementRef, Type } from "@angular/core";
import { ComponentRef, ElementRef, Type, Renderer2 } from "@angular/core";
import { SuiComponentFactory } from "../../../misc/util";
import { SuiPopupController } from "./popup-controller";
import { PopupConfig } from "./popup-config";
......@@ -13,12 +13,13 @@ export class SuiPopupComponentController<T> extends SuiPopupController {
}
}
constructor(element:ElementRef,
constructor(renderer:Renderer2,
element:ElementRef,
componentFactory:SuiComponentFactory,
private _component:Type<T>,
config:PopupConfig) {
super(element, componentFactory, config);
super(renderer, element, componentFactory, config);
this.popup.onClose.subscribe(() => {
if (this._contentComponentRef) {
......
import { ComponentRef, ElementRef, HostListener, OnDestroy } from "@angular/core";
import { ComponentRef, ElementRef, HostListener, OnDestroy, Renderer2 } from "@angular/core";
import { SuiComponentFactory } from "../../../misc/util";
import { PopupConfig, PopupTrigger } from "./popup-config";
import { SuiPopup } from "../components/popup";
......@@ -23,7 +23,11 @@ export abstract class SuiPopupController implements IPopup, OnDestroy {
// `setTimeout` timer pointer for delayed popup open.
private _openingTimeout:number;
constructor(protected _element:ElementRef,
// Function to remove the document click handler.
private _documentListener:() => void;
constructor(private _renderer:Renderer2,
protected _element:ElementRef,
protected _componentFactory:SuiComponentFactory,
config:PopupConfig) {
......@@ -37,6 +41,9 @@ export abstract class SuiPopupController implements IPopup, OnDestroy {
this.popup.onClose.subscribe(() => {
this._componentRef.instance.positioningService.destroy();
this._componentFactory.detachFromApplication(this._componentRef);
// Remove the document click handler
this._documentListener();
});
}
......@@ -68,6 +75,8 @@ export abstract class SuiPopupController implements IPopup, OnDestroy {
// Attach a reference to the anchor element. We do it here because IE11 loves to complain.
this.popup.anchor = this._element;
this._documentListener = this._renderer.listen("document", "click", (e:MouseEvent) => this.onDocumentClick(e));
// Start popup open transition.
this.popup.open();
......@@ -142,7 +151,7 @@ export abstract class SuiPopupController implements IPopup, OnDestroy {
}
}
@HostListener("document:click", ["$event"])
// @HostListener("document:click", ["$event"])
public onDocumentClick(e:MouseEvent):void {
// If the popup trigger is outside click,
if (this._componentRef && this.popup.config.trigger === PopupTrigger.OutsideClick) {
......
import { Directive, Input, ElementRef, TemplateRef } from "@angular/core";
import { Directive, Input, ElementRef, TemplateRef, Renderer2 } from "@angular/core";
import { ITemplateRefContext, Util, PositioningPlacement, SuiComponentFactory } from "../../../misc/util";
import { SuiPopup } from "../components/popup";
import { PopupConfig, PopupTrigger } from "../classes/popup-config";
......@@ -69,10 +69,11 @@ export class SuiPopupDirective extends SuiPopupController {
this.popup.config.batch(config);
}
constructor(element:ElementRef,
constructor(renderer:Renderer2,
element:ElementRef,
componentFactory:SuiComponentFactory,
popupDefaults:SuiPopupConfig) {
super(element, componentFactory, new PopupConfig(popupDefaults));
super(renderer, element, componentFactory, new PopupConfig(popupDefaults));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment