Skip to content

Commit 2366c26

Browse files
committed
feat(grid): correct aria attributes related to total rows/cols count and indexes
1 parent 22e4fbe commit 2366c26

File tree

5 files changed

+32
-7
lines changed

5 files changed

+32
-7
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -705,12 +705,13 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy, CellT
705705

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

711712
@HostBinding('attr.aria-colindex')
712713
protected get ariaColIndex(): number {
713-
return this.visibleColumnIndex + 1;
714+
return this.column.index + 1;
714715
}
715716

716717
@ViewChild('defaultCell', { read: TemplateRef, static: true })

projects/igniteui-angular/src/lib/grids/grid/grid.component.spec.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { FilteringLogic } from '../../data-operations/filtering-expression.inter
2121
import { IgxTabContentComponent, IgxTabHeaderComponent, IgxTabItemComponent, IgxTabsComponent } from '../../tabs/tabs/public_api';
2222
import { IgxGridRowComponent } from './grid-row.component';
2323
import { ISortingExpression, SortingDirection } from '../../data-operations/sorting-strategy';
24-
import { GRID_SCROLL_CLASS } from '../../test-utils/grid-functions.spec';
24+
import { GRID_SCROLL_CLASS, GridFunctions } from '../../test-utils/grid-functions.spec';
2525
import { AsyncPipe } from '@angular/common';
2626
import { IgxPaginatorComponent, IgxPaginatorContentDirective } from '../../paginator/paginator.component';
2727
import { IGridRowEventArgs, IgxColumnGroupComponent, IgxGridEmptyTemplateDirective, IgxGridFooterComponent, IgxGridLoadingTemplateDirective, IgxGridRow, IgxGroupByRow, IgxSummaryRow } from '../public_api';
@@ -2017,26 +2017,31 @@ describe('IgxGrid Component Tests #grid', () => {
20172017
expect(grid.columns[2].field).toBe('lastName');
20182018
}));
20192019

2020-
it('should specify the correct aria-rowindex and aria-colindex attributes for cells', async () => {
2020+
it('should set correct aria attributes related to total rows/cols count and indexes', async () => {
20212021
const fix = TestBed.createComponent(IgxGridDefaultRenderingComponent);
20222022
fix.componentInstance.initColumnsRows(80, 20);
20232023
fix.detectChanges();
20242024
fix.detectChanges();
20252025

20262026
const grid = fix.componentInstance.grid;
2027+
const gridHeader = GridFunctions.getGridHeader(grid);
2028+
const headerRowElement = gridHeader.nativeElement.querySelector('[role="row"]');
20272029

20282030
grid.navigateTo(50, 16);
20292031
fix.detectChanges();
20302032
await wait();
20312033
fix.detectChanges();
20322034

2035+
expect(headerRowElement.getAttribute('aria-rowindex')).toBe('1');
2036+
expect(grid.nativeElement.getAttribute('aria-rowcount')).toBe('81');
2037+
expect(grid.nativeElement.getAttribute('aria-colcount')).toBe('20');
2038+
20332039
const cell = grid.gridAPI.get_cell_by_index(50, 'col16');
20342040
// The following attributes indicate to assistive technologies which portions
20352041
// of the content are displayed in case not all are rendered,
20362042
// such as with the built-in virtualization of the grid. 1-based index.
2037-
expect(cell.nativeElement.getAttribute('aria-rowindex')).toBe('51');
2043+
expect(cell.nativeElement.getAttribute('aria-rowindex')).toBe('52');
20382044
expect(cell.nativeElement.getAttribute('aria-colindex')).toBe('17');
2039-
20402045
});
20412046
});
20422047

projects/igniteui-angular/src/lib/grids/headers/grid-header-group.component.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
[attr.aria-label]="column.header || column.field"
4848
[attr.aria-expanded]="column.expanded"
4949
[attr.aria-selected]="column.selected"
50+
[attr.aria-colindex]="column.index + 1"
51+
[attr.aria-colspan]="column.children.length"
52+
[attr.aria-rowindex]="1"
5053
[ngClass]="{
5154
'igx-grid-th--pinned-last': hasLastPinnedChildColumn,
5255
'igx-grid-th--pinned-first': hasFirstPinnedChildColumn,

projects/igniteui-angular/src/lib/grids/headers/grid-header-row.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
[class.igx-grid__tr--mrl]="hasMRL">
33

44
<!-- Column headers area -->
5-
<div class="igx-grid__tr" role="row" [style.width.px]="width">
5+
<div class="igx-grid__tr" role="row" [attr.aria-rowindex]="1" [style.width.px]="width">
66

77
<!-- Left column moving area -->
88
@if (grid.moving && grid.columnInDrag && pinnedColumnCollection.length <= 0) {

projects/igniteui-angular/src/lib/grids/headers/grid-header.component.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,22 @@ export class IgxGridHeaderComponent implements DoCheck, OnDestroy {
7979
: this.sortDirection === SortingDirection.Desc ? 'descending' : null;
8080
}
8181

82+
/**
83+
* @hidden
84+
*/
85+
@HostBinding('attr.aria-colindex')
86+
public get ariaColIndx() {
87+
return this.column.index + 1;
88+
}
89+
90+
/**
91+
* @hidden
92+
*/
93+
@HostBinding('attr.aria-rowindex')
94+
public get ariaRowIndx() {
95+
return 1;
96+
}
97+
8298
@HostBinding('class.igx-grid-th')
8399
public get columnGroupStyle() {
84100
return !this.column.columnGroup;

0 commit comments

Comments
 (0)