refactor: enhance breadcrumb component templates for improved readability and functionality

- Updated breadcrumb.component.html and dropdown-breadcrumb.component.html to use structural directives for better readability and maintainability.
- Simplified the rendering of previous nodes and last nodes in the breadcrumb, ensuring proper handling of optional values.
- Removed unnecessary imports in dropdown-breadcrumb.component.ts to streamline the component's dependencies.
This commit is contained in:
Denys Vuika
2026-02-26 09:47:42 +00:00
parent 710fa104bd
commit 6ce65aeb4e
3 changed files with 89 additions and 89 deletions
@@ -5,8 +5,8 @@
role="navigation" role="navigation"
[attr.aria-label]="'BREADCRUMB.ARIA-LABEL.BREADCRUMB' | translate" [attr.aria-label]="'BREADCRUMB.ARIA-LABEL.BREADCRUMB' | translate"
> >
@if (hasPreviousNodes()) {
<button <button
*ngIf="hasPreviousNodes()"
tabindex="0" tabindex="0"
class="adf-breadcrumb-dropdown-trigger" class="adf-breadcrumb-dropdown-trigger"
(click)="open()" (click)="open()"
@@ -17,30 +17,30 @@
<mat-icon [class.adf-isRoot]="!hasPreviousNodes()" class="adf-breadcrumb-dropdown-trigger-arrow" adf-icon="arrow_drop_down" /> <mat-icon [class.adf-isRoot]="!hasPreviousNodes()" class="adf-breadcrumb-dropdown-trigger-arrow" adf-icon="arrow_drop_down" />
</div> </div>
</button> </button>
<mat-select <mat-select
#dropdown #dropdown
*ngIf="hasPreviousNodes()"
class="adf-breadcrumb-dropdown-path" class="adf-breadcrumb-dropdown-path"
tabindex="-1" tabindex="-1"
role="button" role="button"
> >
@for (node of previousNodes; track node.id) {
<mat-option <mat-option
*ngFor="let node of previousNodes"
(click)="onRoutePathClick(node, $event)" (click)="onRoutePathClick(node, $event)"
(onSelectionChange)="onRouteClick(node)" (onSelectionChange)="onRouteClick(node)"
class="adf-breadcrumb-path-option" class="adf-breadcrumb-path-option"
[disabled]="readOnly" [disabled]="readOnly"
> >
{{ node.name | translate }} {{ node.name ?? '' | translate }}
</mat-option> </mat-option>
}
</mat-select> </mat-select>
}
@for (item of lastNodes; track item.id; let last = $last) {
<div <div
*ngFor="let item of lastNodes; let last = last"
[class.adf-active]="last" [class.adf-active]="last"
[ngSwitch]="breadcrumbItemIsAnchor(last)" [ngSwitch]="breadcrumbItemIsAnchor(last)"
title="{{ item.name | translate }}" title="{{ item.name ?? '' | translate }}"
class="adf-breadcrumb-item"> class="adf-breadcrumb-item">
<a <a
*ngSwitchCase="true" *ngSwitchCase="true"
@@ -49,7 +49,7 @@
class="adf-breadcrumb-item-anchor" class="adf-breadcrumb-item-anchor"
(click)="onRoutePathClick(item, $event)" (click)="onRoutePathClick(item, $event)"
> >
{{ item.name | translate }} {{ item.name ?? '' | translate }}
</a> </a>
<div *ngSwitchDefault class="adf-breadcrumb-item-current" aria-current="location"> <div *ngSwitchDefault class="adf-breadcrumb-item-current" aria-current="location">
@@ -58,6 +58,7 @@
<mat-icon class="adf-breadcrumb-item-chevron" *ngIf="!last" adf-icon="chevron_right" /> <mat-icon class="adf-breadcrumb-item-chevron" *ngIf="!last" adf-icon="chevron_right" />
</div> </div>
}
</nav> </nav>
<nav <nav
@@ -68,7 +69,7 @@
> >
<div class="adf-breadcrumb-item adf-active" role="group"> <div class="adf-breadcrumb-item adf-active" role="group">
<div class="adf-breadcrumb-item-current"> <div class="adf-breadcrumb-item-current">
{{ root | translate }} {{ root ?? '' | translate }}
</div> </div>
</div> </div>
</nav> </nav>
@@ -1,7 +1,7 @@
<nav *ngIf="route.length > 0" class="adf-dropdown-breadcrumb-container" @if (route.length > 0) {
<nav class="adf-dropdown-breadcrumb-container"
role="navigation" role="navigation"
[attr.aria-label]="'BREADCRUMB.ARIA-LABEL.BREADCRUMB' | translate"> [attr.aria-label]="'BREADCRUMB.ARIA-LABEL.BREADCRUMB' | translate">
<button <button
id="dropdown-breadcrumb-button" id="dropdown-breadcrumb-button"
[tabindex]="hasPreviousNodes() ? 0 : -1" [tabindex]="hasPreviousNodes() ? 0 : -1"
@@ -13,36 +13,35 @@
data-automation-id="dropdown-breadcrumb-trigger"> data-automation-id="dropdown-breadcrumb-trigger">
<mat-icon class="adf-dropdown-breadcrumb-icon" [class.adf-isRoot]="!hasPreviousNodes()" adf-icon="folder" /> <mat-icon class="adf-dropdown-breadcrumb-icon" [class.adf-isRoot]="!hasPreviousNodes()" adf-icon="folder" />
</button> </button>
<mat-icon class="adf-dropdown-breadcrumb-icon adf-dropdown-breadcrumb-item-chevron" adf-icon="chevron_right" /> <mat-icon class="adf-dropdown-breadcrumb-icon adf-dropdown-breadcrumb-item-chevron" adf-icon="chevron_right" />
<div class="adf-dropdown-breadcrumb-path"> <div class="adf-dropdown-breadcrumb-path">
@if (hasPreviousNodes()) {
<mat-select <mat-select
#dropdown #dropdown
*ngIf="hasPreviousNodes()"
panelClass="adf-breadcrumb-dropdown-panel" panelClass="adf-breadcrumb-dropdown-panel"
class="adf-dropdown-breadcrumb-path-select" class="adf-dropdown-breadcrumb-path-select"
tabindex="-1" tabindex="-1"
role="button" role="button"
data-automation-id="dropdown-breadcrumb-path" data-automation-id="dropdown-breadcrumb-path"
aria-labelledby="dropdown-breadcrumb-button"> aria-labelledby="dropdown-breadcrumb-button">
@for (node of previousNodes; track node) {
<mat-option <mat-option
*ngFor="let node of previousNodes;"
(click)="onRoutePathClick(node, $event)" (click)="onRoutePathClick(node, $event)"
(onSelectionChange)="onRouteClick(node)" (onSelectionChange)="onRouteClick(node)"
class="adf-dropdown-breadcrumb-path-option adf-dropdown-breadcrumb-path-option-node" class="adf-dropdown-breadcrumb-path-option adf-dropdown-breadcrumb-path-option-node"
data-automation-class="dropdown-breadcrumb-path-option" data-automation-class="dropdown-breadcrumb-path-option"
[disabled]="readOnly"> [disabled]="readOnly">
{{ node.name | translate }} {{ node.name ?? '' | translate }}
</mat-option> </mat-option>
}
</mat-select> </mat-select>
}
</div> </div>
<span <span
class="adf-current-folder" class="adf-current-folder"
[class.adf-isRoot]="!hasPreviousNodes()" [class.adf-isRoot]="!hasPreviousNodes()"
data-automation-id="current-folder" data-automation-id="current-folder"
aria-current="location">{{ currentNode.name }} aria-current="location">{{ currentNode.name }}
</span> </span>
</nav> </nav>
}
@@ -19,13 +19,13 @@ import { Component, OnChanges, ViewChild, ViewEncapsulation } from '@angular/cor
import { MatSelect, MatSelectModule } from '@angular/material/select'; import { MatSelect, MatSelectModule } from '@angular/material/select';
import { PathElement, Node } from '@alfresco/js-api'; import { PathElement, Node } from '@alfresco/js-api';
import { BreadcrumbComponent } from './breadcrumb.component'; import { BreadcrumbComponent } from './breadcrumb.component';
import { CommonModule } from '@angular/common';
import { TranslatePipe } from '@ngx-translate/core'; import { TranslatePipe } from '@ngx-translate/core';
import { IconModule } from '@alfresco/adf-core'; import { IconModule } from '@alfresco/adf-core';
@Component({ @Component({
selector: 'adf-dropdown-breadcrumb', selector: 'adf-dropdown-breadcrumb',
imports: [CommonModule, IconModule, MatSelectModule, TranslatePipe], imports: [IconModule, MatSelectModule, TranslatePipe],
templateUrl: './dropdown-breadcrumb.component.html', templateUrl: './dropdown-breadcrumb.component.html',
styleUrls: ['./dropdown-breadcrumb.component.scss'], styleUrls: ['./dropdown-breadcrumb.component.scss'],
encapsulation: ViewEncapsulation.None, encapsulation: ViewEncapsulation.None,