Skip to content

Commit

Permalink
Merge pull request #13810 from anlampe/overlay-panel-hiding-when-sele…
Browse files Browse the repository at this point in the history
…cting-dopdown-option

OverlayPanel: Fix regression #14120 detect click on scrollbar, prevent hiding when selecting dropdown options
  • Loading branch information
cetincakiroglu authored Dec 13, 2023
2 parents e48ab18 + d1a2d1d commit 4d6e817
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/app/components/overlaypanel/overlaypanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import { Subscription } from 'rxjs';
role="dialog"
[attr.aria-modal]="overlayVisible"
>
<div class="p-overlaypanel-content" (click)="onContentClick()" (mousedown)="onContentClick()">
<div class="p-overlaypanel-content" (click)="onContentClick($event)" (mousedown)="onContentClick($event)">
<ng-content></ng-content>
<ng-container *ngTemplateOutlet="contentTemplate"></ng-container>
</div>
Expand Down Expand Up @@ -230,10 +230,11 @@ export class OverlayPanel implements AfterContentInit, OnDestroy {
const documentTarget: any = this.el ? this.el.nativeElement.ownerDocument : this.document;

this.documentClickListener = this.renderer.listen(documentTarget, documentEvent, (event) => {
if (!this.container?.contains(event.target) && this.target !== event.target && !this.target.contains(event.target)) {
if (!this.container?.contains(event.target) && this.target !== event.target && !this.target.contains(event.target) && !this.selfClick) {
this.hide();
}

this.selfClick = false;
this.cd.markForCheck();
});
}
Expand Down Expand Up @@ -298,8 +299,9 @@ export class OverlayPanel implements AfterContentInit, OnDestroy {
this.selfClick = true;
}

onContentClick() {
this.selfClick = true;
onContentClick(event: MouseEvent) {
const targetElement = event.target as HTMLElement;
this.selfClick = event.offsetX < targetElement.clientWidth && event.offsetY < targetElement.clientHeight;
}

hasTargetChanged(event: any, target: any) {
Expand Down

0 comments on commit 4d6e817

Please sign in to comment.