Skip to content

Commit 083ad44

Browse files
Merge pull request #16128 from IgniteUI/bpachilova/column-headers-a11y-15962-19.2.x
Address grids column headers accessibility issues - active descendant, what is announced by SRs - 19.2.x
2 parents 79f4bb9 + 0d2d82d commit 083ad44

31 files changed

+450
-62
lines changed

projects/igniteui-angular/src/lib/grids/cell.component.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,17 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy, CellT
703703
}
704704
}
705705

706+
@HostBinding('attr.aria-rowindex')
707+
protected get ariaRowIndex(): number {
708+
// +2 because aria-rowindex is 1-based and the first row is the header
709+
return this.rowIndex + 2;
710+
}
711+
712+
@HostBinding('attr.aria-colindex')
713+
protected get ariaColIndex(): number {
714+
return this.column.index + 1;
715+
}
716+
706717
@ViewChild('defaultCell', { read: TemplateRef, static: true })
707718
protected defaultCellTemplate: TemplateRef<any>;
708719

projects/igniteui-angular/src/lib/grids/grid-base.directive.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1808,6 +1808,15 @@ export abstract class IgxGridBaseDirective implements GridType,
18081808
@HostBinding('class.igx-grid')
18091809
protected baseClass = 'igx-grid';
18101810

1811+
@HostBinding('attr.aria-colcount')
1812+
protected get ariaColCount(): number {
1813+
return this.visibleColumns.length;
1814+
}
1815+
1816+
@HostBinding('attr.aria-rowcount')
1817+
protected get ariaRowCount(): number {
1818+
return this._rendered ? this._rowCount : null;
1819+
}
18111820

18121821
/**
18131822
* Gets/Sets the resource strings.
@@ -2734,13 +2743,10 @@ export abstract class IgxGridBaseDirective implements GridType,
27342743
public get activeDescendant() {
27352744
const activeElem = this.navigation.activeNode;
27362745

2737-
if (!activeElem || !Object.keys(activeElem).length) {
2738-
return this.id;
2746+
if (!activeElem || !Object.keys(activeElem).length || activeElem.row < 0) {
2747+
return null;
27392748
}
2740-
2741-
return activeElem.row < 0 ?
2742-
`${this.id}_${activeElem.row}_${activeElem.mchCache.level}_${activeElem.column}` :
2743-
`${this.id}_${activeElem.row}_${activeElem.column}`;
2749+
return `${this.id}_${activeElem.row}_${activeElem.column}`;
27442750
}
27452751

27462752
/** @hidden @internal */
@@ -3269,6 +3275,7 @@ export abstract class IgxGridBaseDirective implements GridType,
32693275
private _sortDescendingHeaderIconTemplate: TemplateRef<IgxGridHeaderTemplateContext> = null;
32703276
private _gridSize: Size = Size.Large;
32713277
private _defaultRowHeight = 50;
3278+
private _rowCount: number;
32723279

32733280
/**
32743281
* @hidden @internal
@@ -4090,6 +4097,7 @@ export abstract class IgxGridBaseDirective implements GridType,
40904097
if (this.hasColumnsToAutosize) {
40914098
this.autoSizeColumnsInView();
40924099
}
4100+
this._calculateRowCount();
40934101
this._rendered = true;
40944102
});
40954103
Promise.resolve().then(() => this.rendered.next(true));
@@ -6732,6 +6740,7 @@ export abstract class IgxGridBaseDirective implements GridType,
67326740

67336741
this.initColumns(this._columns, (col: IgxColumnComponent) => this.columnInit.emit(col));
67346742
this.columnListDiffer.diff(this.columnList);
6743+
this._calculateRowCount();
67356744

67366745
this.columnList.changes
67376746
.pipe(takeUntil(this.destroy$))
@@ -7955,4 +7964,15 @@ export abstract class IgxGridBaseDirective implements GridType,
79557964
return recreateTreeFromFields(value, this._columns) as IFilteringExpressionsTree;
79567965
}
79577966
}
7967+
7968+
private _calculateRowCount(): void {
7969+
if (this.verticalScrollContainer?.isRemote) {
7970+
this._rowCount = this.verticalScrollContainer.totalItemCount ?? 0;
7971+
} else if (this.paginator) {
7972+
this._rowCount = this.totalRecords ?? 0;
7973+
} else {
7974+
this._rowCount = this.verticalScrollContainer?.igxForOf?.length ?? 0;
7975+
}
7976+
this._rowCount += 1; // include header row
7977+
}
79587978
}

0 commit comments

Comments
 (0)