MCPcopy Create free account
hub / github.com/angular/components / MatStep

Class MatStep

src/material/stepper/stepper.ts:60–122  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

58 },
59})
60export class MatStep extends CdkStep implements ErrorStateMatcher, AfterContentInit, OnDestroy {
61 private _errorStateMatcher = inject(ErrorStateMatcher, {skipSelf: true});
62 private _viewContainerRef = inject(ViewContainerRef);
63 private _isSelected = Subscription.EMPTY;
64
65 /** Content for step label given by `<ng-template matStepLabel>`. */
66 // We need an initializer here to avoid a TS error.
67 @ContentChild(MatStepLabel) override stepLabel: MatStepLabel = undefined!;
68
69 /**
70 * Theme color for the particular step. This API is supported in M2 themes
71 * only, it has no effect in M3 themes. For color customization in M3, see https://material.angular.dev/components/stepper/styling.
72 *
73 * For information on applying color variants in M3, see
74 * https://material.angular.dev/guide/material-2-theming#optional-add-backwards-compatibility-styles-for-color-variants
75 */
76 @Input() color: ThemePalette;
77
78 /** Content that will be rendered lazily. */
79 @ContentChild(MatStepContent, {static: false}) _lazyContent!: MatStepContent;
80
81 /** Currently-attached portal containing the lazy content. */
82 _portal!: TemplatePortal;
83
84 ngAfterContentInit() {
85 this._isSelected = this._stepper.steps.changes
86 .pipe(
87 switchMap(() => {
88 return this._stepper.selectionChange.pipe(
89 map(event => event.selectedStep === this),
90 startWith(this._stepper.selected === this),
91 );
92 }),
93 )
94 .subscribe(isSelected => {
95 if (isSelected && this._lazyContent && !this._portal) {
96 this._portal = new TemplatePortal(this._lazyContent._template, this._viewContainerRef!);
97 }
98 });
99 }
100
101 ngOnDestroy() {
102 this._isSelected.unsubscribe();
103 }
104
105 /** Custom error state matcher that additionally checks for validity of interacted form. */
106 isErrorState(control: AbstractControl | null, form: FormGroupDirective | NgForm | null): boolean {
107 const originalErrorState = this._errorStateMatcher.isErrorState(control, form);
108
109 // Custom error state checks for the validity of form that is not submitted or touched
110 // since user can trigger a form change by calling for another step without directly
111 // interacting with the current form.
112 const customErrorState = !!(control && control.invalid && this.interacted);
113
114 return originalErrorState || customErrorState;
115 }
116
117 isSignalErrorState(field: Field<unknown> | null): boolean {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected