Skip to content

Address grids column headers accessibility issues - active descendant, what is announced by SRs #15982

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: 20.0.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion projects/igniteui-angular/src/lib/grids/cell.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy, CellT
/** @hidden @internal */
@HostBinding('attr.aria-describedby')
public get ariaDescribeBy() {
let describeBy = (this.gridID + '_' + this.column.field).replace('.', '_');
let describeBy = this.column.headerCell?.id || '';
if (this.isInvalid) {
describeBy += ' ' + this.ariaErrorMessage;
}
Expand Down Expand Up @@ -699,6 +699,17 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy, CellT
}
}

@HostBinding('attr.aria-rowindex')
protected get ariaRowIndex(): number {
// +2 because aria-rowindex is 1-based and the first row is the header
return this.rowIndex + 2;
}

@HostBinding('attr.aria-colindex')
protected get ariaColIndex(): number {
return this.column.index + 1;
}

@ViewChild('defaultCell', { read: TemplateRef, static: true })
protected defaultCellTemplate: TemplateRef<any>;

Expand Down
32 changes: 26 additions & 6 deletions projects/igniteui-angular/src/lib/grids/grid-base.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1839,6 +1839,15 @@ export abstract class IgxGridBaseDirective implements GridType,
@HostBinding('class.igx-grid')
protected baseClass = 'igx-grid';

@HostBinding('attr.aria-colcount')
protected get ariaColCount(): number {
return this.visibleColumns.length;
}

@HostBinding('attr.aria-rowcount')
protected get ariaRowCount(): number {
return this._rendered ? this._rowCount : null;
}

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

if (!activeElem || !Object.keys(activeElem).length) {
return this.id;
if (!activeElem || !Object.keys(activeElem).length || activeElem.row < 0) {
return null;
}

return activeElem.row < 0 ?
`${this.id}_${activeElem.row}_${activeElem.mchCache.level}_${activeElem.column}` :
`${this.id}_${activeElem.row}_${activeElem.column}`;
return `${this.id}_${activeElem.row}_${activeElem.column}`;
}

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

/**
* @hidden @internal
Expand Down Expand Up @@ -4123,6 +4130,7 @@ export abstract class IgxGridBaseDirective implements GridType,
if (this.hasColumnsToAutosize) {
this.autoSizeColumnsInView();
}
this._calculateRowCount();
this._rendered = true;
});
Promise.resolve().then(() => this.rendered.next(true));
Expand Down Expand Up @@ -6765,6 +6773,7 @@ export abstract class IgxGridBaseDirective implements GridType,

this.initColumns(this._columns, (col: IgxColumnComponent) => this.columnInit.emit(col));
this.columnListDiffer.diff(this.columnList);
this._calculateRowCount();

this.columnList.changes
.pipe(takeUntil(this.destroy$))
Expand Down Expand Up @@ -7988,4 +7997,15 @@ export abstract class IgxGridBaseDirective implements GridType,
return recreateTreeFromFields(value, this._columns) as IFilteringExpressionsTree;
}
}

private _calculateRowCount(): void {
if (this.verticalScrollContainer?.isRemote) {
this._rowCount = this.verticalScrollContainer.totalItemCount ?? 0;
} else if (this.paginator) {
this._rowCount = this.totalRecords ?? 0;
} else {
this._rowCount = this.verticalScrollContainer?.igxForOf?.length ?? 0;
}
this._rowCount += 1; // include header row
}
}
Loading
Loading