1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-14 15:23:33 +00:00
Files
browser/libs/angular/src/directives/fallback-src.directive.ts
Will Martin 84bafe5e73 [CL-104] fix overlay + virtual scroll view recycling bug (#6179)
* close menu overlay when no longer visible

* prevent infinite loop in fallback-src directive

* block scrolling when menu is open

* disable view recycling; use reposition strategy
2023-10-12 10:34:53 -04:00

21 lines
561 B
TypeScript

import { Directive, ElementRef, HostListener, Input } from "@angular/core";
@Directive({
selector: "[appFallbackSrc]",
})
export class FallbackSrcDirective {
@Input("appFallbackSrc") appFallbackSrc: string;
/** Only try setting the fallback once. This prevents an infinite loop if the fallback itself is missing. */
private tryFallback = true;
constructor(private el: ElementRef) {}
@HostListener("error") onError() {
if (this.tryFallback) {
this.el.nativeElement.src = this.appFallbackSrc;
this.tryFallback = false;
}
}
}