Merge pull request #3367 from Andrea-Guevara/AccessibilityInVocabularyTreeview

Accessibility in vocabulary treeview
This commit is contained in:
Tim Donohue
2024-12-19 12:08:37 -06:00
committed by GitHub
2 changed files with 28 additions and 10 deletions

View File

@@ -2,20 +2,24 @@
<div class="treeview-header row mb-1"> <div class="treeview-header row mb-1">
<div class="col-12"> <div class="col-12">
<div class="input-group"> <div class="input-group">
<input type="text" class="form-control" [(ngModel)]="searchText" (keyup.enter)="search()" <input #searchInput type="text" class="form-control" [(ngModel)]="searchText" (keyup.enter)="search()"
[attr.aria-label]="'vocabulary-treeview.search.form.search-placeholder' | translate" [attr.aria-label]="'vocabulary-treeview.search.form.search-placeholder' | translate"
[placeholder]="'vocabulary-treeview.search.form.search-placeholder' | translate"> [placeholder]="'vocabulary-treeview.search.form.search-placeholder' | translate">
<div class="input-group-append" id="button-addon4"> <div class="input-group-append" id="button-addon4">
<button class="btn btn-outline-primary" type="button" (click)="search()" [disabled]="!isSearchEnabled()"> <button class="btn btn-outline-primary" type="button" (click)="search()" [disabled]="!isSearchEnabled()"
[attr.aria-label]="'vocabulary-treeview.search.form.search' | translate">
{{'vocabulary-treeview.search.form.search' | translate}} {{'vocabulary-treeview.search.form.search' | translate}}
</button> </button>
<button class="btn btn-outline-secondary" type="button" (click)="reset()"> <button class="btn btn-outline-secondary" type="button" (click)="reset()"
[attr.aria-label]="'vocabulary-treeview.search.form.reset' | translate">
{{'vocabulary-treeview.search.form.reset' | translate}} {{'vocabulary-treeview.search.form.reset' | translate}}
</button> </button>
<button *ngIf="showAdd && this.vocabularyOptions.closed" class="btn btn-outline-primary" type="button" (click)="add()"> <button *ngIf="showAdd && this.vocabularyOptions.closed" class="btn btn-outline-primary" type="button" (click)="add()"
[attr.aria-label]="'vocabulary-treeview.search.form.add' | translate">
{{'vocabulary-treeview.search.form.add' | translate}} {{'vocabulary-treeview.search.form.add' | translate}}
</button> </button>
<button class="btn btn-outline-primary" type="button" (click)="add()" [disabled]="this.vocabularyOptions.closed"> <button class="btn btn-outline-primary" type="button" (click)="add()" [disabled]="this.vocabularyOptions.closed"
[attr.aria-label]="'vocabulary-treeview.search.form.add' | translate">
{{'vocabulary-treeview.search.form.add' | translate}} {{'vocabulary-treeview.search.form.add' | translate}}
</button> </button>
</div> </div>
@@ -24,9 +28,11 @@
</div> </div>
<div class="treeview-container"> <div class="treeview-container">
<ds-loading *ngIf="loading | async" [showMessage]="false"></ds-loading> <ds-loading *ngIf="loading | async" [showMessage]="false"></ds-loading>
<h2 *ngIf="(loading | async) !== true && dataSource.data.length === 0" class="h4 text-center text-muted mt-4" > <div aria-live="polite">
<span>{{'vocabulary-treeview.search.no-result' | translate}}</span> <h2 *ngIf="(loading | async) !== true && dataSource.data.length === 0" class="h4 text-center text-muted mt-4" >
</h2> <span>{{'vocabulary-treeview.search.no-result' | translate}}</span>
</h2>
</div>
<cdk-tree [dataSource]="dataSource" [treeControl]="treeControl"> <cdk-tree [dataSource]="dataSource" [treeControl]="treeControl">
<!-- Leaf node --> <!-- Leaf node -->
<cdk-tree-node *cdkTreeNodeDef="let node" cdkTreeNodePadding class="d-flex"> <cdk-tree-node *cdkTreeNodeDef="let node" cdkTreeNodePadding class="d-flex">
@@ -91,13 +97,15 @@
</cdk-tree-node> </cdk-tree-node>
<cdk-tree-node *cdkTreeNodeDef="let node; when: isLoadMore" cdkTreeNodePadding> <cdk-tree-node *cdkTreeNodeDef="let node; when: isLoadMore" cdkTreeNodePadding>
<button class="btn btn-outline-secondary btn-sm" (click)="loadMore(node.loadMoreParentItem)"> <button class="btn btn-outline-secondary btn-sm" (click)="loadMore(node.loadMoreParentItem)"
[attr.aria-label]="'vocabulary-treeview.load-more' | translate">
{{'vocabulary-treeview.load-more' | translate}}... {{'vocabulary-treeview.load-more' | translate}}...
</button> </button>
</cdk-tree-node> </cdk-tree-node>
<cdk-tree-node *cdkTreeNodeDef="let node; when: isLoadMoreRoot"> <cdk-tree-node *cdkTreeNodeDef="let node; when: isLoadMoreRoot">
<button class="btn btn-outline-secondary btn-sm" (click)="loadMoreRoot(node)"> <button class="btn btn-outline-secondary btn-sm" (click)="loadMoreRoot(node)"
[attr.aria-label]="'vocabulary-treeview.load-more' | translate">
{{'vocabulary-treeview.load-more' | translate}}... {{'vocabulary-treeview.load-more' | translate}}...
</button> </button>
</cdk-tree-node> </cdk-tree-node>

View File

@@ -8,6 +8,7 @@ import {
} from '@angular/common'; } from '@angular/common';
import { import {
Component, Component,
ElementRef,
EventEmitter, EventEmitter,
Input, Input,
OnChanges, OnChanges,
@@ -15,6 +16,7 @@ import {
OnInit, OnInit,
Output, Output,
SimpleChanges, SimpleChanges,
ViewChild,
} from '@angular/core'; } from '@angular/core';
import { FormsModule } from '@angular/forms'; import { FormsModule } from '@angular/forms';
import { NgbTooltipModule } from '@ng-bootstrap/ng-bootstrap'; import { NgbTooltipModule } from '@ng-bootstrap/ng-bootstrap';
@@ -70,6 +72,11 @@ export type VocabularyTreeItemType = FormFieldMetadataValueObject | VocabularyEn
}) })
export class VocabularyTreeviewComponent implements OnDestroy, OnInit, OnChanges { export class VocabularyTreeviewComponent implements OnDestroy, OnInit, OnChanges {
/**
* Implemented to manage focus on input
*/
@ViewChild('searchInput') searchInput!: ElementRef;
/** /**
* The {@link VocabularyOptions} object * The {@link VocabularyOptions} object
*/ */
@@ -332,6 +339,9 @@ export class VocabularyTreeviewComponent implements OnDestroy, OnInit, OnChanges
this.storedNodeMap = new Map<string, TreeviewFlatNode>(); this.storedNodeMap = new Map<string, TreeviewFlatNode>();
this.vocabularyTreeviewService.restoreNodes(); this.vocabularyTreeviewService.restoreNodes();
} }
if (this.searchInput) {
this.searchInput.nativeElement.focus();
}
} }
add() { add() {