Skip to content

Commit dd5ba17

Browse files
Merge pull request #16096 from IgniteUI/bpachilova/column-headers-a11y-15962-master
Address grids column headers accessibility issues - active descendant, what is announced by SRs - master
2 parents 002707e + e6d9645 commit dd5ba17

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
@@ -1839,6 +1839,15 @@ export abstract class IgxGridBaseDirective implements GridType,
18391839
@HostBinding('class.igx-grid')
18401840
protected baseClass = 'igx-grid';
18411841

1842+
@HostBinding('attr.aria-colcount')
1843+
protected get ariaColCount(): number {
1844+
return this.visibleColumns.length;
1845+
}
1846+
1847+
@HostBinding('attr.aria-rowcount')
1848+
protected get ariaRowCount(): number {
1849+
return this._rendered ? this._rowCount : null;
1850+
}
18421851

18431852
/**
18441853
* Gets/Sets the resource strings.
@@ -2765,13 +2774,10 @@ export abstract class IgxGridBaseDirective implements GridType,
27652774
public get activeDescendant() {
27662775
const activeElem = this.navigation.activeNode;
27672776

2768-
if (!activeElem || !Object.keys(activeElem).length) {
2769-
return this.id;
2777+
if (!activeElem || !Object.keys(activeElem).length || activeElem.row < 0) {
2778+
return null;
27702779
}
2771-
2772-
return activeElem.row < 0 ?
2773-
`${this.id}_${activeElem.row}_${activeElem.mchCache.level}_${activeElem.column}` :
2774-
`${this.id}_${activeElem.row}_${activeElem.column}`;
2780+
return `${this.id}_${activeElem.row}_${activeElem.column}`;
27752781
}
27762782

27772783
/** @hidden @internal */
@@ -3302,6 +3308,7 @@ export abstract class IgxGridBaseDirective implements GridType,
33023308
private _sortDescendingHeaderIconTemplate: TemplateRef<IgxGridHeaderTemplateContext> = null;
33033309
private _gridSize: Size = Size.Large;
33043310
private _defaultRowHeight = 50;
3311+
private _rowCount: number;
33053312

33063313
/**
33073314
* @hidden @internal
@@ -4123,6 +4130,7 @@ export abstract class IgxGridBaseDirective implements GridType,
41234130
if (this.hasColumnsToAutosize) {
41244131
this.autoSizeColumnsInView();
41254132
}
4133+
this._calculateRowCount();
41264134
this._rendered = true;
41274135
});
41284136
Promise.resolve().then(() => this.rendered.next(true));
@@ -6765,6 +6773,7 @@ export abstract class IgxGridBaseDirective implements GridType,
67656773

67666774
this.initColumns(this._columns, (col: IgxColumnComponent) => this.columnInit.emit(col));
67676775
this.columnListDiffer.diff(this.columnList);
6776+
this._calculateRowCount();
67686777

67696778
this.columnList.changes
67706779
.pipe(takeUntil(this.destroy$))
@@ -7988,4 +7997,15 @@ export abstract class IgxGridBaseDirective implements GridType,
79887997
return recreateTreeFromFields(value, this._columns) as IFilteringExpressionsTree;
79897998
}
79907999
}
8000+
8001+
private _calculateRowCount(): void {
8002+
if (this.verticalScrollContainer?.isRemote) {
8003+
this._rowCount = this.verticalScrollContainer.totalItemCount ?? 0;
8004+
} else if (this.paginator) {
8005+
this._rowCount = this.totalRecords ?? 0;
8006+
} else {
8007+
this._rowCount = this.verticalScrollContainer?.igxForOf?.length ?? 0;
8008+
}
8009+
this._rowCount += 1; // include header row
8010+
}
79918011
}

0 commit comments

Comments
 (0)