Skip to content

Commit 0d2d82d

Browse files
committed
feat(grid): correct aria attributes related to total rows/cols count and indexes
1 parent d04160e commit 0d2d82d

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, IgxGridFooterComponent, IgxGridRow, IgxGroupByRow, IgxSummaryRow } from '../public_api';
@@ -2005,26 +2005,31 @@ describe('IgxGrid Component Tests #grid', () => {
20052005
expect(grid.columns[2].field).toBe('lastName');
20062006
}));
20072007

2008-
it('should specify the correct aria-rowindex and aria-colindex attributes for cells', async () => {
2008+
it('should set correct aria attributes related to total rows/cols count and indexes', async () => {
20092009
const fix = TestBed.createComponent(IgxGridDefaultRenderingComponent);
20102010
fix.componentInstance.initColumnsRows(80, 20);
20112011
fix.detectChanges();
20122012
fix.detectChanges();
20132013

20142014
const grid = fix.componentInstance.grid;
2015+
const gridHeader = GridFunctions.getGridHeader(grid);
2016+
const headerRowElement = gridHeader.nativeElement.querySelector('[role="row"]');
20152017

20162018
grid.navigateTo(50, 16);
20172019
fix.detectChanges();
20182020
await wait();
20192021
fix.detectChanges();
20202022

2023+
expect(headerRowElement.getAttribute('aria-rowindex')).toBe('1');
2024+
expect(grid.nativeElement.getAttribute('aria-rowcount')).toBe('81');
2025+
expect(grid.nativeElement.getAttribute('aria-colcount')).toBe('20');
2026+
20212027
const cell = grid.gridAPI.get_cell_by_index(50, 'col16');
20222028
// The following attributes indicate to assistive technologies which portions
20232029
// of the content are displayed in case not all are rendered,
20242030
// such as with the built-in virtualization of the grid. 1-based index.
2025-
expect(cell.nativeElement.getAttribute('aria-rowindex')).toBe('51');
2031+
expect(cell.nativeElement.getAttribute('aria-rowindex')).toBe('52');
20262032
expect(cell.nativeElement.getAttribute('aria-colindex')).toBe('17');
2027-
20282033
});
20292034
});
20302035

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)