/// /// Copyright 2015-2026 Micro Focus or one of its affiliates. /// /// Licensed under the Apache License, Version 2.0 (the "License"); /// you may not use this file except in compliance with the License. /// You may obtain a copy of the License at /// /// http://www.apache.org/licenses/LICENSE-2.0 /// /// Unless required by applicable law or agreed to in writing, software /// distributed under the License is distributed on an "AS IS" BASIS, /// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. /// See the License for the specific language governing permissions and /// limitations under the License. /// import { coerceBooleanProperty } from '@angular/cdk/coercion'; import { ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, inject, Input, Output, } from '@angular/core'; import { WizardService } from './wizard.service'; @Component({ selector: 'ux-wizard-step', templateUrl: './wizard-step.component.html', changeDetection: ChangeDetectionStrategy.OnPush, host: { role: 'tabpanel', }, }) export class WizardStepComponent { private readonly _wizardService = inject>(WizardService); private readonly _changeDetector = inject(ChangeDetectorRef); /** The text to be displayed in the wizard step tab. */ @Input() header: string; /** * If set to `true` the 'Next' or 'Finish' button will become disabled when the current step is invalid. * This will override the value set on the `ux-wizard`. */ @Input() disableNextWhenInvalid: boolean | undefined; /** * Defines whether a step is valid. The user will not be able to proceed to the next step if this property has a value of false. * If the new value is false is will also set the visited value to false. */ _valid: boolean = true; @Input() set valid(value: boolean) { this.setValid(value); } get valid(): boolean { return this._valid; } /** * A custom function which returns the validation status for the step. This function will be called when 'Next' or * 'Finish' is clicked. A promise may be returned if asynchronous validation is required. If using this property, * ensure that `disableNextWhenInvalid` is false. */ @Input() validator: () => boolean | Promise; /** * Defines whether or not this step has previously been visited. * A visited step can be clicked on and jumped to at any time. * By default, steps will become 'visited' when the user navigates to a step for the first time. */ @Input() visited: boolean = false; /** Emits when visited changes. */ @Output() visitedChange = new EventEmitter(); set active(value: boolean) { const active = coerceBooleanProperty(value); // store the active state of the step this._active = active; // if the value is true then the step should also be marked as visited if (active && !this.visited) { this.setVisitedAndEmitChangeEvent(true); } // mark for change detection this._changeDetector.markForCheck(); } get active(): boolean { return this._active; } /** * Defines the currently visible step. */ _active: boolean = false; setVisitedAndEmitChangeEvent(value: boolean): void { if (value === this.visited) { return; } this.visited = value; this.visitedChange.emit(value); } protected setValid(value: boolean): void { if (this._valid === value) { return; } this._valid = value; this._wizardService.validChange$.next({ step: this, valid: value }); } }