File
Implements
Index
Properties
|
|
Methods
|
|
Inputs
|
|
Outputs
|
|
Accessors
|
|
collapsed
|
Type : boolean
|
Default value : false
|
|
compact
|
Type : boolean
|
Default value : false
|
|
horizontal
|
Type : boolean
|
Default value : false
|
|
isForbidden
|
Type : boolean
|
Default value : false
|
|
Methods
getSectionLabel
|
getSectionLabel(id: string)
|
|
Parameters :
Name |
Type |
Optional |
id |
string
|
No
|
|
onKeydown
|
onKeydown($event: KeyboardEvent, undefined: literal type)
|
|
Parameters :
Name |
Type |
Optional |
$event |
KeyboardEvent
|
No
|
literal type
|
No
|
|
requestSection
|
requestSection(undefined: literal type)
|
|
Parameters :
Name |
Type |
Optional |
literal type
|
No
|
|
focusIndex
|
Type : number | null
|
Default value : null
|
|
Accessors
currentSectionIndex
|
getcurrentSectionIndex()
|
|
import { FocusKeyManager } from '@angular/cdk/a11y';
import {
AfterViewInit,
Component,
EventEmitter,
HostBinding,
Input,
OnChanges,
Output,
QueryList,
ViewChildren
} from '@angular/core';
import { SectionConfig, SectionWithState } from './model';
import { StepState } from './navigation-step-state';
import { NavigationStepComponent } from './navigation-step.component';
@Component({
selector: 'frame-navigation-view',
templateUrl: './navigation-view.component.html',
styleUrls: ['./navigation-view.component.scss'],
standalone: false
})
export class NavigationViewComponent implements AfterViewInit, OnChanges {
@HostBinding('class.is-horizontal')
@Input()
horizontal = false;
@Input() collapsed = false;
@Input() compact = false;
@Input() sectionStates: SectionWithState[] = [];
@Input() sections?: SectionConfig;
@Input() isForbidden = false;
@Output() goto = new EventEmitter<string>();
private currentState: SectionWithState | undefined;
mobileBreadcrumbsText: string | undefined;
focusIndex: number | null = null;
@ViewChildren(NavigationStepComponent) items!: QueryList<NavigationStepComponent>;
private keyManager!: FocusKeyManager<NavigationStepComponent>;
onKeydown($event: KeyboardEvent, { sectionId }: { sectionId: string }) {
const key = $event.key;
if (key === 'Enter') {
this.requestSection({ sectionId });
$event.preventDefault();
} else {
this.keyManager.onKeydown($event);
this.focusIndex = this.getFocusIndex();
}
}
ngOnChanges() {
this.currentState = this.getCurrentState();
this.mobileBreadcrumbsText = this.getMobileBreadcrumbsText();
// this.keyManager is not initialized on the first call of ngOnChanges()
if (this.keyManager) {
this.keyManager.updateActiveItem(this.currentSectionIndex);
}
}
ngAfterViewInit() {
this.keyManager = new FocusKeyManager(this.items)
.withWrap()
.skipPredicate((item) => item.isPending)
.withHorizontalOrientation('ltr')
.withVerticalOrientation();
}
getSectionLabel(id: string) {
const section = this.sections?.get(id);
return section?.label;
}
private getCurrentState(): SectionWithState | undefined {
return this.sectionStates.find((item) => item.state === StepState.CURRENT);
}
private getFocusIndex() {
return this.keyManager.activeItemIndex;
}
get currentSectionIndex() {
return this.currentState ? this.sectionStates.indexOf(this.currentState) : -1;
}
requestSection({ sectionId }: { sectionId: string }) {
this.goto.emit(sectionId);
}
private getMobileBreadcrumbsText(): string | undefined {
let text;
if (this.currentState) {
text =
$localize`Step ` +
`${this.currentSectionIndex + 1}/${this.sectionStates.length}: ${this.getSectionLabel(
this.currentState.sectionId
)}`;
}
return text;
}
}
<ng-container *ngIf="compact">
<div class="compact" *ngIf="mobileBreadcrumbsText">{{ mobileBreadcrumbsText }}</div>
</ng-container>
<ng-container *ngIf="!compact">
<div class="navigation-steps" role="tablist">
<ng-container *ngFor="let section of sectionStates; let i = index">
<frame-navigation-step
(click)="requestSection(section)"
(keydown)="onKeydown($event, section)"
[tabindex]="focusIndex === i ? 0 : -1"
[state]="section.state"
[label]="getSectionLabel(section.sectionId)"
[hideLabel]="collapsed"
[horizontal]="horizontal"
[isForbidden]="isForbidden"
>
</frame-navigation-step>
</ng-container>
</div>
</ng-container>
:host {
display: block;
}
:host(.is-horizontal) {
.navigation-steps {
display: flex;
}
.dots,
.labels {
display: flex;
}
}
.compact {
text-align: center;
font-size: var(--progress-indicator-mobile-font-size);
line-height: var(--progress-indicator-mobile-line-height);
}
Legend
Html element with directive