Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(popup): Fixed focus events on popup #243

Merged
merged 2 commits into from
Aug 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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