[v0.0.1] Fixes Drag Event in ClickOutside Directive
This commit is contained in:
@@ -97,6 +97,7 @@ export class HeaderComponent {
|
|||||||
|
|
||||||
this.navSliderStatus = false;
|
this.navSliderStatus = false;
|
||||||
this.userSliderStatus = false;
|
this.userSliderStatus = false;
|
||||||
|
this.profileDropdownState = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private createSignupPopup() {
|
private createSignupPopup() {
|
||||||
@@ -119,6 +120,7 @@ export class HeaderComponent {
|
|||||||
|
|
||||||
this.navSliderStatus = false;
|
this.navSliderStatus = false;
|
||||||
this.userSliderStatus = false;
|
this.userSliderStatus = false;
|
||||||
|
this.profileDropdownState = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private closeLoginPopup() {
|
private closeLoginPopup() {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { DOCUMENT } from '@angular/common';
|
import { DOCUMENT } from '@angular/common';
|
||||||
import { AfterViewInit, Directive, ElementRef, EventEmitter, Inject, Input, OnDestroy, Output, ViewChild } from '@angular/core';
|
import { AfterViewInit, Directive, ElementRef, EventEmitter, Inject, Input, OnDestroy, Output, ViewChild } from '@angular/core';
|
||||||
import { filter, fromEvent, Subscription } from 'rxjs';
|
import { combineLatest, combineLatestWith, filter, fromEvent, merge, Subscription } from 'rxjs';
|
||||||
|
|
||||||
@Directive({
|
@Directive({
|
||||||
selector: '[appClickedOutside]'
|
selector: '[appClickedOutside]'
|
||||||
@@ -19,7 +19,7 @@ export class ClickedOutsideDirective implements AfterViewInit, OnDestroy {
|
|||||||
@Output()
|
@Output()
|
||||||
clickOutside: EventEmitter<void> = new EventEmitter();
|
clickOutside: EventEmitter<void> = new EventEmitter();
|
||||||
|
|
||||||
clickListener!: Subscription;
|
eventListener!: Subscription;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private element: ElementRef,
|
private element: ElementRef,
|
||||||
@@ -28,20 +28,25 @@ export class ClickedOutsideDirective implements AfterViewInit, OnDestroy {
|
|||||||
|
|
||||||
ngAfterViewInit(): void {
|
ngAfterViewInit(): void {
|
||||||
|
|
||||||
|
const mouseDownListener$ = fromEvent(document, 'mousedown');
|
||||||
|
const mouseUpListener$ = fromEvent(document,'mouseup');
|
||||||
|
|
||||||
|
this.eventListener = mouseUpListener$.pipe(
|
||||||
this.clickListener = fromEvent(this.document, 'click')
|
combineLatestWith(mouseDownListener$),
|
||||||
.pipe(
|
filter(([downClick, upClick]) => {
|
||||||
filter((event) => {
|
return (downClick.target as HTMLElement)
|
||||||
return !this.isInside(event.target as HTMLElement) || this.includedList(event.target as HTMLElement);
|
.contains(this.element.nativeElement) && (!this.isInside(
|
||||||
|
upClick.target as HTMLElement
|
||||||
|
) || this.includedList(upClick.target as HTMLElement));
|
||||||
})
|
})
|
||||||
). subscribe( () => {
|
). subscribe( () => {
|
||||||
!this.clickOutsideStopWatching && this.clickOutside.emit();
|
!this.clickOutsideStopWatching && this.clickOutside.emit();
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy(): void {
|
ngOnDestroy(): void {
|
||||||
this.clickListener?.unsubscribe();
|
this.eventListener?.unsubscribe();
|
||||||
}
|
}
|
||||||
|
|
||||||
private isInside(elementToCheck: HTMLElement): boolean {
|
private isInside(elementToCheck: HTMLElement): boolean {
|
||||||
|
|||||||
Reference in New Issue
Block a user