Skip to content

Commit 35eae55

Browse files
committedDec 1, 2021
fix(modal): mouseup and mousedown different targets trigger onClickHandler
1 parent b9d204c commit 35eae55

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed
 

‎projects/coreui-angular/src/lib/modal/modal/modal.component.ts

+14-3
Original file line numberDiff line numberDiff line change
@@ -223,14 +223,25 @@ export class ModalComponent implements OnInit, OnDestroy {
223223
}
224224
}
225225

226+
private mouseDownTarget: EventTarget | null = null;
227+
228+
@HostListener('mousedown', ['$event'])
229+
public onMouseDownHandler($event: MouseEvent): void {
230+
this.mouseDownTarget = $event.target;
231+
}
232+
226233
@HostListener('click', ['$event'])
227234
public onClickHandler($event: MouseEvent): void {
235+
$event.stopPropagation();
236+
if (this.mouseDownTarget !== $event.target) {
237+
this.mouseDownTarget = null;
238+
return;
239+
}
228240
if (this.backdrop === 'static') {
229241
this.setStaticBackdrop();
230-
} else {
231-
this.modalService.toggle({show: false, modal: this});
242+
return;
232243
}
233-
$event.stopPropagation();
244+
this.modalService.toggle({show: false, modal: this});
234245
}
235246

236247
ngOnInit(): void {

0 commit comments

Comments
 (0)
Please sign in to comment.