Skip to content

Commit 573e9bc

Browse files
committed
main - a6a70f6 build: add missing dependency (#30229)
1 parent f0f9cf5 commit 573e9bc

File tree

8 files changed

+90
-57
lines changed

8 files changed

+90
-57
lines changed

docs-content/examples-highlighted/material/sidenav/sidenav-responsive/sidenav-responsive-example-html.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
@if (shouldRun) {
2-
<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;example-container&quot;</span> [<span class="hljs-attr">class.example-is-mobile</span>]=<span class="hljs-string">&quot;mobileQuery.matches&quot;</span>&gt;</span>
2+
<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;example-container&quot;</span> [<span class="hljs-attr">class.example-is-mobile</span>]=<span class="hljs-string">&quot;isMobile()&quot;</span>&gt;</span>
33
<span class="hljs-tag">&lt;<span class="hljs-name">mat-toolbar</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;example-toolbar&quot;</span>&gt;</span>
44
<span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">mat-icon-button</span> (<span class="hljs-attr">click</span>)=<span class="hljs-string">&quot;snav.toggle()&quot;</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">mat-icon</span>&gt;</span>menu<span class="hljs-tag">&lt;/<span class="hljs-name">mat-icon</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
55
<span class="hljs-tag">&lt;<span class="hljs-name">h1</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;example-app-name&quot;</span>&gt;</span>Responsive App<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
66
<span class="hljs-tag">&lt;/<span class="hljs-name">mat-toolbar</span>&gt;</span>
77

88
<span class="hljs-tag">&lt;<span class="hljs-name">mat-sidenav-container</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;example-sidenav-container&quot;</span>
9-
[<span class="hljs-attr">style.marginTop.px</span>]=<span class="hljs-string">&quot;mobileQuery.matches ? 56 : 0&quot;</span>&gt;</span>
10-
<span class="hljs-tag">&lt;<span class="hljs-name">mat-sidenav</span> #<span class="hljs-attr">snav</span> [<span class="hljs-attr">mode</span>]=<span class="hljs-string">&quot;mobileQuery.matches ? &#x27;over&#x27; : &#x27;side&#x27;&quot;</span>
11-
[<span class="hljs-attr">fixedInViewport</span>]=<span class="hljs-string">&quot;mobileQuery.matches&quot;</span> <span class="hljs-attr">fixedTopGap</span>=<span class="hljs-string">&quot;56&quot;</span>&gt;</span>
9+
[<span class="hljs-attr">style.marginTop.px</span>]=<span class="hljs-string">&quot;isMobile() ? 56 : 0&quot;</span>&gt;</span>
10+
<span class="hljs-tag">&lt;<span class="hljs-name">mat-sidenav</span> #<span class="hljs-attr">snav</span> [<span class="hljs-attr">mode</span>]=<span class="hljs-string">&quot;isMobile() ? &#x27;over&#x27; : &#x27;side&#x27;&quot;</span>
11+
[<span class="hljs-attr">fixedInViewport</span>]=<span class="hljs-string">&quot;isMobile()&quot;</span> <span class="hljs-attr">fixedTopGap</span>=<span class="hljs-string">&quot;56&quot;</span>&gt;</span>
1212
<span class="hljs-tag">&lt;<span class="hljs-name">mat-nav-list</span>&gt;</span>
1313
@for (nav of fillerNav; track nav) {
1414
<span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">mat-list-item</span> <span class="hljs-attr">routerLink</span>=<span class="hljs-string">&quot;.&quot;</span>&gt;</span>{{nav}}<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
11
<span class="hljs-keyword">import</span> {MediaMatcher} <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@angular/cdk/layout&#x27;</span>;
2-
<span class="hljs-keyword">import</span> {ChangeDetectorRef, Component, OnDestroy, inject} <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@angular/core&#x27;</span>;
2+
<span class="hljs-keyword">import</span> {Component, OnDestroy, inject, signal} <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@angular/core&#x27;</span>;
33
<span class="hljs-keyword">import</span> {MatListModule} <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@angular/material/list&#x27;</span>;
44
<span class="hljs-keyword">import</span> {MatSidenavModule} <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@angular/material/sidenav&#x27;</span>;
55
<span class="hljs-keyword">import</span> {MatIconModule} <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@angular/material/icon&#x27;</span>;
66
<span class="hljs-keyword">import</span> {MatButtonModule} <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@angular/material/button&#x27;</span>;
77
<span class="hljs-keyword">import</span> {MatToolbarModule} <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@angular/material/toolbar&#x27;</span>;
8+
<span class="hljs-keyword">import</span> {RouterLink} <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@angular/router&#x27;</span>;
89

910
<span class="hljs-comment">/** <span class="hljs-doctag">@title </span>Responsive sidenav */</span>
1011
<span class="hljs-meta">@Component</span>({
1112
<span class="hljs-attr">selector</span>: <span class="hljs-string">&#x27;sidenav-responsive-example&#x27;</span>,
1213
<span class="hljs-attr">templateUrl</span>: <span class="hljs-string">&#x27;sidenav-responsive-example.html&#x27;</span>,
1314
<span class="hljs-attr">styleUrl</span>: <span class="hljs-string">&#x27;sidenav-responsive-example.css&#x27;</span>,
14-
<span class="hljs-attr">imports</span>: [MatToolbarModule, MatButtonModule, MatIconModule, MatSidenavModule, MatListModule],
15+
<span class="hljs-attr">imports</span>: [
16+
MatToolbarModule,
17+
MatButtonModule,
18+
MatIconModule,
19+
MatSidenavModule,
20+
MatListModule,
21+
RouterLink,
22+
],
1523
})
1624
<span class="hljs-keyword">export</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">SidenavResponsiveExample</span> <span class="hljs-title">implements</span> <span class="hljs-title">OnDestroy</span> </span>{
17-
<span class="hljs-attr">mobileQuery</span>: MediaQueryList;
25+
<span class="hljs-keyword">protected</span> <span class="hljs-keyword">readonly</span> fillerNav = <span class="hljs-built_in">Array</span>.from({<span class="hljs-attr">length</span>: <span class="hljs-number">50</span>}, <span class="hljs-function">(<span class="hljs-params">_, i</span>) =&gt;</span> <span class="hljs-string">`Nav Item <span class="hljs-subst">${i + <span class="hljs-number">1</span>}</span>`</span>);
1826

19-
fillerNav = <span class="hljs-built_in">Array</span>.from({<span class="hljs-attr">length</span>: <span class="hljs-number">50</span>}, <span class="hljs-function">(<span class="hljs-params">_, i</span>) =&gt;</span> <span class="hljs-string">`Nav Item <span class="hljs-subst">${i + <span class="hljs-number">1</span>}</span>`</span>);
20-
21-
fillerContent = <span class="hljs-built_in">Array</span>.from(
27+
<span class="hljs-keyword">protected</span> <span class="hljs-keyword">readonly</span> fillerContent = <span class="hljs-built_in">Array</span>.from(
2228
{<span class="hljs-attr">length</span>: <span class="hljs-number">50</span>},
2329
<span class="hljs-function">() =&gt;</span>
2430
<span class="hljs-string">`Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut
@@ -28,20 +34,25 @@
2834
cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.`</span>,
2935
);
3036

31-
<span class="hljs-keyword">private</span> _mobileQueryListener: <span class="hljs-function">() =&gt;</span> <span class="hljs-built_in">void</span>;
37+
<span class="hljs-keyword">protected</span> <span class="hljs-keyword">readonly</span> isMobile = signal(<span class="hljs-literal">true</span>);
38+
39+
<span class="hljs-keyword">private</span> <span class="hljs-keyword">readonly</span> _mobileQuery: MediaQueryList;
40+
<span class="hljs-keyword">private</span> <span class="hljs-keyword">readonly</span> _mobileQueryListener: <span class="hljs-function">() =&gt;</span> <span class="hljs-built_in">void</span>;
3241

3342
<span class="hljs-function"><span class="hljs-title">constructor</span>(<span class="hljs-params"></span>)</span> {
34-
<span class="hljs-keyword">const</span> changeDetectorRef = inject(ChangeDetectorRef);
3543
<span class="hljs-keyword">const</span> media = inject(MediaMatcher);
3644

37-
<span class="hljs-built_in">this</span>.mobileQuery = media.matchMedia(<span class="hljs-string">&#x27;(max-width: 600px)&#x27;</span>);
38-
<span class="hljs-built_in">this</span>._mobileQueryListener = <span class="hljs-function">() =&gt;</span> changeDetectorRef.detectChanges();
39-
<span class="hljs-built_in">this</span>.mobileQuery.addListener(<span class="hljs-built_in">this</span>._mobileQueryListener);
45+
<span class="hljs-built_in">this</span>._mobileQuery = media.matchMedia(<span class="hljs-string">&#x27;(max-width: 600px)&#x27;</span>);
46+
<span class="hljs-built_in">this</span>.isMobile.set(<span class="hljs-built_in">this</span>._mobileQuery.matches);
47+
<span class="hljs-built_in">this</span>._mobileQueryListener = <span class="hljs-function">() =&gt;</span> <span class="hljs-built_in">this</span>.isMobile.set(<span class="hljs-built_in">this</span>._mobileQuery.matches);
48+
<span class="hljs-built_in">this</span>._mobileQuery.addEventListener(<span class="hljs-string">&#x27;change&#x27;</span>, <span class="hljs-built_in">this</span>._mobileQueryListener);
4049
}
4150

4251
ngOnDestroy(): <span class="hljs-built_in">void</span> {
43-
<span class="hljs-built_in">this</span>.mobileQuery.removeListener(<span class="hljs-built_in">this</span>._mobileQueryListener);
52+
<span class="hljs-built_in">this</span>._mobileQuery.removeEventListener(<span class="hljs-string">&#x27;change&#x27;</span>, <span class="hljs-built_in">this</span>._mobileQueryListener);
4453
}
4554

46-
shouldRun = <span class="hljs-regexp">/(^|.)(stackblitz|webcontainer).(io|com)$/</span>.test(<span class="hljs-built_in">window</span>.location.host);
55+
<span class="hljs-keyword">protected</span> <span class="hljs-keyword">readonly</span> shouldRun = <span class="hljs-regexp">/(^|.)(stackblitz|webcontainer).(io|com)$/</span>.test(
56+
<span class="hljs-built_in">window</span>.location.host,
57+
);
4758
}

docs-content/examples-source/material/sidenav/sidenav-responsive/sidenav-responsive-example.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
@if (shouldRun) {
2-
<div class="example-container" [class.example-is-mobile]="mobileQuery.matches">
2+
<div class="example-container" [class.example-is-mobile]="isMobile()">
33
<mat-toolbar class="example-toolbar">
44
<button mat-icon-button (click)="snav.toggle()"><mat-icon>menu</mat-icon></button>
55
<h1 class="example-app-name">Responsive App</h1>
66
</mat-toolbar>
77

88
<mat-sidenav-container class="example-sidenav-container"
9-
[style.marginTop.px]="mobileQuery.matches ? 56 : 0">
10-
<mat-sidenav #snav [mode]="mobileQuery.matches ? 'over' : 'side'"
11-
[fixedInViewport]="mobileQuery.matches" fixedTopGap="56">
9+
[style.marginTop.px]="isMobile() ? 56 : 0">
10+
<mat-sidenav #snav [mode]="isMobile() ? 'over' : 'side'"
11+
[fixedInViewport]="isMobile()" fixedTopGap="56">
1212
<mat-nav-list>
1313
@for (nav of fillerNav; track nav) {
1414
<a mat-list-item routerLink=".">{{nav}}</a>
Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
11
import {MediaMatcher} from '@angular/cdk/layout';
2-
import {ChangeDetectorRef, Component, OnDestroy, inject} from '@angular/core';
2+
import {Component, OnDestroy, inject, signal} from '@angular/core';
33
import {MatListModule} from '@angular/material/list';
44
import {MatSidenavModule} from '@angular/material/sidenav';
55
import {MatIconModule} from '@angular/material/icon';
66
import {MatButtonModule} from '@angular/material/button';
77
import {MatToolbarModule} from '@angular/material/toolbar';
8+
import {RouterLink} from '@angular/router';
89

910
/** @title Responsive sidenav */
1011
@Component({
1112
selector: 'sidenav-responsive-example',
1213
templateUrl: 'sidenav-responsive-example.html',
1314
styleUrl: 'sidenav-responsive-example.css',
14-
imports: [MatToolbarModule, MatButtonModule, MatIconModule, MatSidenavModule, MatListModule],
15+
imports: [
16+
MatToolbarModule,
17+
MatButtonModule,
18+
MatIconModule,
19+
MatSidenavModule,
20+
MatListModule,
21+
RouterLink,
22+
],
1523
})
1624
export class SidenavResponsiveExample implements OnDestroy {
17-
mobileQuery: MediaQueryList;
25+
protected readonly fillerNav = Array.from({length: 50}, (_, i) => `Nav Item ${i + 1}`);
1826

19-
fillerNav = Array.from({length: 50}, (_, i) => `Nav Item ${i + 1}`);
20-
21-
fillerContent = Array.from(
27+
protected readonly fillerContent = Array.from(
2228
{length: 50},
2329
() =>
2430
`Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut
@@ -28,20 +34,25 @@ export class SidenavResponsiveExample implements OnDestroy {
2834
cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.`,
2935
);
3036

31-
private _mobileQueryListener: () => void;
37+
protected readonly isMobile = signal(true);
38+
39+
private readonly _mobileQuery: MediaQueryList;
40+
private readonly _mobileQueryListener: () => void;
3241

3342
constructor() {
34-
const changeDetectorRef = inject(ChangeDetectorRef);
3543
const media = inject(MediaMatcher);
3644

37-
this.mobileQuery = media.matchMedia('(max-width: 600px)');
38-
this._mobileQueryListener = () => changeDetectorRef.detectChanges();
39-
this.mobileQuery.addListener(this._mobileQueryListener);
45+
this._mobileQuery = media.matchMedia('(max-width: 600px)');
46+
this.isMobile.set(this._mobileQuery.matches);
47+
this._mobileQueryListener = () => this.isMobile.set(this._mobileQuery.matches);
48+
this._mobileQuery.addEventListener('change', this._mobileQueryListener);
4049
}
4150

4251
ngOnDestroy(): void {
43-
this.mobileQuery.removeListener(this._mobileQueryListener);
52+
this._mobileQuery.removeEventListener('change', this._mobileQueryListener);
4453
}
4554

46-
shouldRun = /(^|.)(stackblitz|webcontainer).(io|com)$/.test(window.location.host);
55+
protected readonly shouldRun = /(^|.)(stackblitz|webcontainer).(io|com)$/.test(
56+
window.location.host,
57+
);
4758
}

0 commit comments

Comments
 (0)