1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-09 13:10:17 +00:00

fix provider issue when used in router outlet

This commit is contained in:
William Martin
2025-04-24 11:35:22 -04:00
parent ad7df1d654
commit 897ede94b1
2 changed files with 14 additions and 13 deletions

View File

@@ -27,7 +27,7 @@ export class LayoutComponent {
protected sideNavService = inject(SideNavService);
protected drawerPortal = inject(DrawerService).portal;
mainContent = viewChild.required<ElementRef<HTMLElement>>("main");
private mainContent = viewChild.required<ElementRef<HTMLElement>>("main");
protected focusMainContent() {
this.mainContent().nativeElement.focus();

View File

@@ -2,33 +2,34 @@ import { Directionality } from "@angular/cdk/bidi";
import { CdkVirtualScrollable, ScrollDispatcher, VIRTUAL_SCROLLABLE } from "@angular/cdk/scrolling";
import { Directive, ElementRef, NgZone, Optional } from "@angular/core";
import { LayoutComponent } from "./layout.component";
@Directive({
selector: "cdk-virtual-scroll-viewport[bitScrollLayout]",
standalone: true,
providers: [{ provide: VIRTUAL_SCROLLABLE, useExisting: ScrollLayoutDirective }],
})
export class ScrollLayoutDirective extends CdkVirtualScrollable {
constructor(
private layout: LayoutComponent,
scrollDispatcher: ScrollDispatcher,
ngZone: NgZone,
@Optional() dir: Directionality,
) {
super(layout.mainContent(), scrollDispatcher, ngZone, dir);
private mainRef: ElementRef<HTMLElement>;
constructor(scrollDispatcher: ScrollDispatcher, ngZone: NgZone, @Optional() dir: Directionality) {
const mainEl = document.querySelector("main")!;
if (!mainEl) {
// eslint-disable-next-line no-console
console.error("HTML main element must be an ancestor of [bitScrollLayout]");
}
const mainRef = new ElementRef(mainEl);
super(mainRef, scrollDispatcher, ngZone, dir);
this.mainRef = mainRef;
}
override getElementRef(): ElementRef<HTMLElement> {
return this.layout.mainContent();
return this.mainRef;
}
override measureBoundingClientRectWithScrollOffset(
from: "left" | "top" | "right" | "bottom",
): number {
return (
this.layout.mainContent().nativeElement.getBoundingClientRect()[from] -
this.measureScrollOffset(from)
this.mainRef.nativeElement.getBoundingClientRect()[from] - this.measureScrollOffset(from)
);
}
}