Skip to content

Commit

Permalink
Refactored fixed for #11341
Browse files Browse the repository at this point in the history
  • Loading branch information
cagataycivici committed Mar 28, 2022
1 parent e1b0481 commit 4c58e15
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/app/components/styleclass/styleclass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,17 +168,23 @@ export class StyleClass implements AfterViewInit, OnDestroy {
bindDocumentListener() {
if (!this.documentListener) {
this.documentListener = this.renderer.listen(this.el.nativeElement.ownerDocument, 'click', event => {
if (getComputedStyle(this.target).getPropertyValue('position') === 'static') {
if (!this.isVisible() || getComputedStyle(this.target).getPropertyValue('position') === 'static')
this.unbindDocumentListener();
}
else if (this.target.offsetParent !== null && !this.el.nativeElement.isSameNode(event.target)
&& !this.el.nativeElement.contains(event.target) && !this.target.contains(event.target)) {
else if (this.isOutsideClick(event))
this.leave();
}
});
}
}

isVisible() {
return this.target.offsetParent !== null;
}

isOutsideClick(event: MouseEvent) {
return !this.el.nativeElement.isSameNode(event.target) && !this.el.nativeElement.contains(event.target) &&
!this.target.contains(<HTMLElement> event.target);
}

unbindDocumentListener() {
if (this.documentListener) {
this.documentListener();
Expand Down

0 comments on commit 4c58e15

Please sign in to comment.