I would like to suggest simplifying the popup implementation by including a default mechanism to close the popup when the user clicks outside its boundaries.
Currently, this functionality requires additional code, such as the example below:
Documentation reference:
https://www.telerik.com/kendo-angular-ui/components/popup/closing#on-document-click-or-escape
@ViewChild("anchor", { read: ElementRef }) public anchor: ElementRef;
@ViewChild("popup", { read: ElementRef }) public popup: ElementRef;
@HostListener("document:keydown", ["$event"])
public keydown(event: KeyboardEvent): void {
if (event.code === "Escape") {
this.closePopup();
}
}
@HostListener("document:click", ["$event"])
public documentClick(event: KeyboardEvent): void {
if (!this.contains(event.target)) {
this. closePopup();
}
}
private contains(target: EventTarget): boolean {
return (
this.anchor.nativeElement.contains(target) ||
(this.popup ? this.popup.nativeElement.contains(target) : false)
);
}
Including this functionality as a default in the popup component would eliminate the need to write repetitive code for every use of the popup component.
Thank you for considering this enhancement.
Kind regards,
Herman Fransen