Skip to content

Commit 7f8a729

Browse files
authored
fix(material/schematics): resolve issues in navigation schematic (#33590)
Resolves the following issues in the navigation schematic: 1. We were using observables instead of signals for `isHandset`. 2. We were using `color` on the toolbar. 3. One of the `standalone` checks in the generated test was flipped. Fixes #33381.
1 parent d26a0be commit 7f8a729

3 files changed

Lines changed: 13 additions & 15 deletions

File tree

‎src/material/schematics/ng-generate/navigation/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.html.template‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
@let isHandset = this.isHandset();
2+
13
<mat-sidenav-container class="sidenav-container">
24
<mat-sidenav #drawer class="sidenav" fixedInViewport
3-
[attr.role]="(isHandset$ | async) ? 'dialog' : 'navigation'"
4-
[mode]="(isHandset$ | async) ? 'over' : 'side'"
5-
[opened]="(isHandset$ | async) === false">
5+
[attr.role]="isHandset ? 'dialog' : 'navigation'"
6+
[mode]="isHandset ? 'over' : 'side'"
7+
[opened]="isHandset === false">
68
<mat-toolbar>Menu</mat-toolbar>
79
<mat-nav-list>
810
<a mat-list-item <%= routing ? 'routerLink="/"' : 'href="#"' %>>Link 1</a>
@@ -11,8 +13,8 @@
1113
</mat-nav-list>
1214
</mat-sidenav>
1315
<mat-sidenav-content>
14-
<mat-toolbar color="primary">
15-
@if (isHandset$ | async) {
16+
<mat-toolbar>
17+
@if (isHandset) {
1618
<button
1719
type="button"
1820
aria-label="Toggle sidenav"

‎src/material/schematics/ng-generate/navigation/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.spec.ts.template‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { <%= classify(name) %>Component } from './<%= dasherize(name) %>.compone
99

1010
describe('<%= classify(name) %>Component', () => {
1111
let component: <%= classify(name) %>Component;
12-
let fixture: ComponentFixture<<%= classify(name) %>Component>;<% if(standalone) { %>
12+
let fixture: ComponentFixture<<%= classify(name) %>Component>;<% if(!standalone) { %>
1313

1414
beforeEach(waitForAsync(() => {
1515
TestBed.configureTestingModule({

‎src/material/schematics/ng-generate/navigation/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.ts.template‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { Component, inject<% if(!!viewEncapsulation) { %>, ViewEncapsulation<% }%><% if(changeDetection !== 'Default') { %>, ChangeDetectionStrategy<% }%> } from '@angular/core';
2+
import { toSignal } from '@angular/core/rxjs-interop';
23
import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout';<% if(standalone) { %>
3-
import { AsyncPipe } from '@angular/common';
44
import { MatToolbarModule } from '@angular/material/toolbar';
55
import { MatButtonModule } from '@angular/material/button';
66
import { MatSidenavModule } from '@angular/material/sidenav';
77
import { MatListModule } from '@angular/material/list';
88
import { MatIconModule } from '@angular/material/icon';<% } %>
99
import { Observable } from 'rxjs';
10-
import { map, shareReplay } from 'rxjs/operators';
10+
import { map } from 'rxjs/operators';
1111

1212
@Component({
1313
selector: '<%= selector %>',<% if(inlineTemplate) { %>
@@ -27,16 +27,12 @@ import { map, shareReplay } from 'rxjs/operators';
2727
MatSidenavModule,
2828
MatListModule,
2929
MatIconModule,
30-
AsyncPipe,
3130
]<% } else { %>,
3231
standalone: false<% } %>
3332
})
3433
export class <%= classify(name) %>Component {
35-
private breakpointObserver = inject(BreakpointObserver);
34+
private readonly breakpointObserver = inject(BreakpointObserver);
3635

37-
isHandset$: Observable<boolean> = this.breakpointObserver.observe(Breakpoints.Handset)
38-
.pipe(
39-
map(result => result.matches),
40-
shareReplay()
41-
);
36+
readonly isHandset = toSignal(this.breakpointObserver.observe(Breakpoints.Handset)
37+
.pipe(map(result => result.matches)), { initialValue: false });
4238
}

0 commit comments

Comments
 (0)