Skip to content

Commit

Permalink
fix(popup): Fixed focus events on popup (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
edcarroll authored and mcosta74 committed Aug 11, 2017
1 parent 0720b9f commit abeffa7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
10 changes: 7 additions & 3 deletions src/modules/popup/classes/popup-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,13 @@ export abstract class SuiPopupController implements IPopup, OnDestroy {
}
}

@HostListener("focusout")
private onFocusOut():void {
if (this.popup.config.trigger === PopupTrigger.Focus) {
@HostListener("focusout", ["$event"])
private onFocusOut(e:any):void {
console.log(e.relatedTarget);
if (!this._element.nativeElement.contains(e.relatedTarget) &&
!this.popup.elementRef.nativeElement.contains(e.relatedTarget) &&
this.popup.config.trigger === PopupTrigger.Focus) {

this.close();
}
}
Expand Down
14 changes: 6 additions & 8 deletions src/modules/popup/components/popup.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, ViewChild, ViewContainerRef, ElementRef, EventEmitter, HostListener } from "@angular/core";
import { Component, ViewChild, ViewContainerRef, ElementRef, EventEmitter, HostListener, HostBinding } from "@angular/core";
import { PositioningService, IDynamicClasses } from "../../../misc/util";
import { TransitionController, TransitionDirection, Transition } from "../../transition";
import { IPopup } from "../classes/popup-controller";
Expand Down Expand Up @@ -122,13 +122,18 @@ export class SuiPopup implements IPopup {
@ViewChild("templateSibling", { read: ViewContainerRef })
public templateSibling:ViewContainerRef;

@HostBinding("attr.tabindex")
private _tabindex:number;

constructor(public elementRef:ElementRef) {
this.transitionController = new TransitionController(false);

this._isOpen = false;

this.onOpen = new EventEmitter<void>();
this.onClose = new EventEmitter<void>();

this._tabindex = 0;
}

public open():void {
Expand Down Expand Up @@ -187,13 +192,6 @@ export class SuiPopup implements IPopup {
}
}

@HostListener("mousedown", ["$event"])
public onMouseDown(e:MouseEvent):void {
if (!this.elementRef.nativeElement.contains(e.target)) {
e.preventDefault();
}
}

@HostListener("click", ["$event"])
public onClick(event:MouseEvent):void {
// Makes sense here, as the popup shouldn't be attached to any DOM element.
Expand Down

0 comments on commit abeffa7

Please sign in to comment.