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:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user