Skip to content

Commit 987fe7f

Browse files
committed
feat(grids): add aria-sort attribute to column headers + test checks
1 parent dee439a commit 987fe7f

File tree

5 files changed

+25
-0
lines changed

5 files changed

+25
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ describe('IgxGrid - Grid Sorting #grid', () => {
4141
spyOn(grid.sortingDone, 'emit').and.callThrough();
4242
const currentColumn = 'Name';
4343
const lastNameColumn = 'LastName';
44+
const nameHeaderCell = GridFunctions.getColumnHeader(currentColumn, fixture);
4445
grid.sort({ fieldName: currentColumn, dir: SortingDirection.Asc, ignoreCase: false });
4546
tick(30);
4647
fixture.detectChanges();
@@ -50,6 +51,7 @@ describe('IgxGrid - Grid Sorting #grid', () => {
5051
sortingExpressions: grid.sortingExpressions,
5152
owner: grid
5253
});
54+
expect(nameHeaderCell.attributes['aria-sort']).toEqual('ascending');
5355

5456
expect(grid.getCellByColumn(0, currentColumn).value).toEqual('ALex');
5557
expect(grid.getCellByColumn(0, lastNameColumn).value).toEqual('Smith');
@@ -72,13 +74,15 @@ describe('IgxGrid - Grid Sorting #grid', () => {
7274

7375
it('Should sort grid descending by column name', () => {
7476
const currentColumn = 'Name';
77+
const nameHeaderCell = GridFunctions.getColumnHeader(currentColumn, fixture);
7578
// Ignore case on sorting set to false
7679
grid.sort({ fieldName: currentColumn, dir: SortingDirection.Desc, ignoreCase: false });
7780
fixture.detectChanges();
7881

7982

8083
expect(grid.getCellByColumn(0, currentColumn).value).toEqual('Rick');
8184
expect(grid.getCellByColumn(grid.data.length - 1, currentColumn).value).toEqual('ALex');
85+
expect(nameHeaderCell.attributes['aria-sort']).toEqual('descending');
8286

8387
// Ignore case on sorting set to true
8488
grid.sort({ fieldName: currentColumn, dir: SortingDirection.Desc, ignoreCase: true });
@@ -476,6 +480,7 @@ describe('IgxGrid - Grid Sorting #grid', () => {
476480
sortingExpressions: grid.sortingExpressions,
477481
owner: grid
478482
});
483+
expect(firstHeaderCell.attributes['aria-sort']).toEqual('ascending');
479484

480485
const firstRowFirstCell = GridFunctions.getCurrentCellFromGrid(grid, 0, 0);
481486
const firstRowSecondCell = GridFunctions.getCurrentCellFromGrid(grid, 0, 1);
@@ -506,6 +511,7 @@ describe('IgxGrid - Grid Sorting #grid', () => {
506511
sortingExpressions: grid.sortingExpressions,
507512
owner: grid
508513
});
514+
expect(firstHeaderCell.attributes['aria-sort']).toEqual('ascending');
509515

510516
GridFunctions.clickHeaderSortIcon(firstHeaderCell);
511517
tick(30);
@@ -516,6 +522,7 @@ describe('IgxGrid - Grid Sorting #grid', () => {
516522
sortingExpressions: grid.sortingExpressions,
517523
owner: grid
518524
});
525+
expect(firstHeaderCell.attributes['aria-sort']).toEqual('descending');
519526

520527
const firstRowFirstCell = GridFunctions.getCurrentCellFromGrid(grid, 0, 0);
521528
const firstRowSecondCell = GridFunctions.getCurrentCellFromGrid(grid, 0, 1);
@@ -562,6 +569,7 @@ describe('IgxGrid - Grid Sorting #grid', () => {
562569
expect(GridFunctions.getColumnSortingIndex(GridFunctions.getColumnHeader('ID', fixture))).toBeNull();
563570
expect(grid.sorting.emit).toHaveBeenCalledTimes(3);
564571
expect(grid.sortingDone.emit).toHaveBeenCalledTimes(3);
572+
expect(firstHeaderCell.attributes['aria-sort']).toEqual(undefined);
565573
}));
566574

567575
it('Should have a valid sorting icon when sorting using the API.', () => {

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@ export class IgxGridHeaderComponent implements DoCheck, OnDestroy {
6363
return this.column.selected;
6464
}
6565

66+
/**
67+
* Returns the `aria-sort` of the header.
68+
*/
69+
@HostBinding('attr.aria-sort')
70+
public get ariaSort() {
71+
return this.sortDirection === SortingDirection.Asc ? 'ascending'
72+
: this.sortDirection === SortingDirection.Desc ? 'descending' : null;
73+
}
74+
6675
@HostBinding('class.igx-grid-th')
6776
public get columnGroupStyle() {
6877
return !this.column.columnGroup;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ describe('IgxHierarchicalGrid Integration #hGrid', () => {
342342
const icon = GridFunctions.getHeaderSortIcon(childHeader);
343343
expect(icon).not.toBeNull();
344344
expect(icon.nativeElement.textContent.toLowerCase().trim()).toBe('arrow_downward');
345+
expect(childHeader.attributes['aria-sort']).toEqual('descending');
345346
}));
346347
});
347348

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,6 +1398,7 @@ describe('IgxPivotGrid #pivotGrid', () => {
13981398
let expectedOrder = [829, undefined, 240, 293, 296];
13991399
let columnValues = pivotGrid.dataView.map(x => (x as IPivotGridRecord).aggregationValues.get('USA-UnitsSold'));
14001400
expect(columnValues).toEqual(expectedOrder);
1401+
expect(headerCell.attributes['aria-sort']).toBe('ascending');
14011402

14021403
headerCell = GridFunctions.getColumnHeader('USA-UnitsSold', fixture);
14031404
// sort desc
@@ -1407,6 +1408,7 @@ describe('IgxPivotGrid #pivotGrid', () => {
14071408
expectedOrder = [829, 296, 293, 240, undefined];
14081409
columnValues = pivotGrid.dataView.map(x => (x as IPivotGridRecord).aggregationValues.get('USA-UnitsSold'));
14091410
expect(columnValues).toEqual(expectedOrder);
1411+
expect(headerCell.attributes['aria-sort']).toBe('descending');
14101412

14111413
// remove sort
14121414
headerCell = GridFunctions.getColumnHeader('USA-UnitsSold', fixture);

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,15 @@ describe('IgxTreeGrid - Sorting #tGrid', () => {
2626
it('should sort descending all treeGrid levels by column name through API', () => {
2727
treeGrid.sort({ fieldName: 'Name', dir: SortingDirection.Desc, ignoreCase: false,
2828
strategy: DefaultSortingStrategy.instance() });
29+
const nameHeaderCell = GridFunctions.getColumnHeader('Name', fix);
30+
2931
fix.detectChanges();
3032

3133
// Verify first level records are desc sorted
3234
expect(treeGrid.getCellByColumn(0, 'Name').value).toEqual('Yang Wang');
3335
expect(treeGrid.getCellByColumn(1, 'Name').value).toEqual('John Winchester');
3436
expect(treeGrid.getCellByColumn(8, 'Name').value).toEqual('Ana Sanders');
37+
expect(nameHeaderCell.attributes['aria-sort']).toEqual('descending');
3538

3639
// Verify second level records are desc sorted
3740
expect(treeGrid.getCellByColumn(2, 'Name').value).toEqual('Thomas Hardy');
@@ -205,6 +208,7 @@ describe('IgxTreeGrid - Sorting #tGrid', () => {
205208
expect(treeGrid.getCellByColumn(0, 'Name').value).toEqual('Yang Wang');
206209
expect(treeGrid.getCellByColumn(1, 'Name').value).toEqual('John Winchester');
207210
expect(treeGrid.getCellByColumn(8, 'Name').value).toEqual('Ana Sanders');
211+
expect(header.attributes['aria-sort']).toEqual('descending');
208212

209213
// Verify second level records are desc sorted
210214
expect(treeGrid.getCellByColumn(2, 'Name').value).toEqual('Thomas Hardy');
@@ -226,6 +230,7 @@ describe('IgxTreeGrid - Sorting #tGrid', () => {
226230
expect(treeGrid.getCellByColumn(0, 'Age').value).toEqual(42);
227231
expect(treeGrid.getCellByColumn(2, 'Age').value).toEqual(55);
228232
expect(treeGrid.getCellByColumn(9, 'Age').value).toEqual(61);
233+
expect(header.attributes['aria-sort']).toEqual('ascending');
229234

230235
// Verify second level records are asc sorted
231236
expect(treeGrid.getCellByColumn(3, 'Age').value).toEqual(29);

0 commit comments

Comments
 (0)