Skip to content

Commit

Permalink
OverlayPanel: Fix regression #13605 & #13601 detect click on scrollba…
Browse files Browse the repository at this point in the history
…r, prevent hiding e.g. when selecting dropdown options
  • Loading branch information
anlampe committed Nov 2, 2023
1 parent 3b6ff1f commit d1a2d1d
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 d1a2d1d

Please sign in to comment.