1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-06 00:13:28 +00:00

[CL-609] Close side nav when breakpoint changes (#15062)

* Close side nav when breakpoint changes

* Leverage side-nave listener instead

* Remove effect inside pipe

* Reuse isSmallScreen
This commit is contained in:
Mark Youssef
2025-09-29 07:19:52 -07:00
committed by GitHub
parent 90fb57817a
commit 018b4d5eb4

View File

@@ -1,4 +1,5 @@
import { Injectable } from "@angular/core";
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
import { BehaviorSubject, Observable, combineLatest, fromEvent, map, startWith } from "rxjs";
@Injectable({
@@ -8,10 +9,20 @@ export class SideNavService {
private _open$ = new BehaviorSubject<boolean>(!window.matchMedia("(max-width: 768px)").matches);
open$ = this._open$.asObservable();
isOverlay$ = combineLatest([this.open$, media("(max-width: 768px)")]).pipe(
private isSmallScreen$ = media("(max-width: 768px)");
isOverlay$ = combineLatest([this.open$, this.isSmallScreen$]).pipe(
map(([open, isSmallScreen]) => open && isSmallScreen),
);
constructor() {
this.isSmallScreen$.pipe(takeUntilDestroyed()).subscribe((isSmallScreen) => {
if (isSmallScreen) {
this.setClose();
}
});
}
get open() {
return this._open$.getValue();
}