Skip to content

Commit d1ddba8

Browse files
EXUI-1539/38: Add aria-sort to table headers (#1736)
* Add aria-sort to table headers in search-result.component * resolve sonar lint issues * remove aria-label from column header table * Move aria-sort to TH element * Fix double table (exui-1538), simplify isSortAscending to fix multiple comlumns showing as sorted * Change ver name * Unit test for new function * Resolve empty header accessibilty issue * fix unit test * version updated --------- Co-authored-by: RiteshHMCTS <[email protected]> Co-authored-by: Ritesh Dsouza <[email protected]>
1 parent d802955 commit d1ddba8

File tree

6 files changed

+52
-43
lines changed

6 files changed

+52
-43
lines changed

RELEASE-NOTES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## RELEASE NOTES
22

3+
### Version 7.0.49
4+
**EXUI-1538** MC - (Level-A) : DAC_Tables_01
5+
**EXUI-1539** MC - (Level-A) : DAC_Sortable_Tables_01
6+
37
### Version 7.0.48
48
**EXUI-1952** Add time to date display in case file view
59

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hmcts/ccd-case-ui-toolkit",
3-
"version": "7.0.48",
3+
"version": "7.0.49",
44
"engines": {
55
"node": ">=18.19.0"
66
},

projects/ccd-case-ui-toolkit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hmcts/ccd-case-ui-toolkit",
3-
"version": "7.0.48",
3+
"version": "7.0.49",
44
"engines": {
55
"node": ">=18.19.0"
66
},

projects/ccd-case-ui-toolkit/src/lib/shared/components/search-result/search-result.component.html

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ <h2 class="heading-h2" id="search-result-heading__text" tabindex="-1">{{ (caseSt
1010
</strong>
1111
</div>
1212

13-
<div *ngIf="(hasResults() || hasDrafts())" class="pagination-top"
14-
[attr.aria-label]="getTotalResults() + ' results have been found' | rpxTranslate" role="status">
15-
<span class="text-16" id="search-result-summary__text">{{'Showing' | rpxTranslate}}
13+
<div *ngIf="(hasResults() || hasDrafts())" class="pagination-top">
14+
<output [attr.aria-label]="getTotalResults() + ' results have been found' | rpxTranslate"></output>
15+
<span class="text-16" id="search-result-summary__text">{{'Showing' | rpxTranslate}}
1616
<span class="govuk-!-font-weight-bold">{{ getFirstResult() }}</span>
1717
{{'to' | rpxTranslate}}
1818
<span class="govuk-!-font-weight-bold">{{ getLastResult() }}</span>
@@ -33,22 +33,18 @@ <h2 class="heading-h2" id="search-result-heading__text" tabindex="-1">{{ (caseSt
3333
</label>
3434
</div>
3535
</th>
36-
<th *ngFor="let col of resultView.columns">
37-
<table class="search-result-column-header"
38-
[attr.aria-label]="('Sort by ' + col.label + ' ' + isSortAscending(col)? 'ascending' : 'descending') | rpxTranslate">
39-
<tr>
40-
<th>
41-
<div class="search-result-column-label" (click)="sort(col)">
42-
{{col.label | rpxTranslate}}
43-
</div>
44-
<div *ngIf="comparator(col)" class="search-result-column-sort">
45-
<a (click)="sort(col)" class="sort-widget" [innerHTML]="sortWidget(col)" href="javascript:void(0)"></a>
46-
</div>
47-
</th>
48-
</tr>
49-
</table>
36+
<th *ngFor="let col of resultView.columns" class="search-result-column-header"
37+
[attr.aria-sort]="isSortAscending(col) === null ? null : (isSortAscending(col) ? 'ascending' : 'descending')">
38+
<div>
39+
<div class="search-result-column-label" (click)="sort(col)" (keyup)="noop()">
40+
{{col.label | rpxTranslate}}
41+
</div>
42+
<div *ngIf="comparator(col)" class="search-result-column-sort">
43+
<a (click)="sort(col)" class="sort-widget" [innerHTML]="sortWidget(col)" href="javascript:void(0)"></a>
44+
</div>
45+
</div>
5046
</th>
51-
<th *ngIf="activityEnabled()" style="width: 110px;"></th>
47+
<th *ngIf="activityEnabled()" style="width: 110px;">&ZeroWidthSpace;</th>
5248
</tr>
5349
</thead>
5450

projects/ccd-case-ui-toolkit/src/lib/shared/components/search-result/search-result.component.spec.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ import {
1414
Jurisdiction,
1515
PaginationMetadata,
1616
SearchResultView,
17-
SearchResultViewItem
17+
SearchResultViewColumn,
18+
SearchResultViewItem,
19+
SortOrder
1820
} from '../../domain';
1921
import { CaseReferencePipe, SortSearchResultPipe } from '../../pipes';
2022
import { ActivityService, BrowserService, FieldsUtils, SearchResultViewItemComparatorFactory, SessionStorageService } from '../../services';
@@ -350,7 +352,7 @@ describe('SearchResultComponent', () => {
350352

351353
it('should render an case activity column with header', () => {
352354
const headRow = de.query(By.css('div>table>thead>tr th:nth-child(4)'));
353-
expect(headRow.nativeElement.textContent).toBe('');
355+
expect(headRow.nativeElement.textContent).not.toBeNull();
354356
});
355357

356358
it('should not render an case activity column when activity is disabled', () => {
@@ -901,5 +903,26 @@ describe('SearchResultComponent', () => {
901903
const pagination = de.query(By.css('div.pagination-top'));
902904
expect(pagination).toBeFalsy();
903905
});
906+
907+
it('should return true if the column is sorted in ascending order', () => {
908+
const column = { case_field_id: 'PersonFirstName' } as SearchResultViewColumn;
909+
component.consumerSortParameters = { column: 'PersonFirstName', order: SortOrder.ASCENDING, type: 'Text' };
910+
911+
expect(component.isSortAscending(column)).toBe(true);
912+
});
913+
914+
it('should return false if the column is sorted in descending order', () => {
915+
const column = { case_field_id: 'PersonFirstName' } as SearchResultViewColumn;
916+
component.consumerSortParameters = { column: 'PersonFirstName', order: SortOrder.DESCENDING, type: 'Text' };
917+
918+
expect(component.isSortAscending(column)).toBe(false);
919+
});
920+
921+
it('should return null if the column is not sorted', () => {
922+
const column = { case_field_id: 'PersonFirstName' } as SearchResultViewColumn;
923+
component.consumerSortParameters = { column: 'PersonLastName', order: SortOrder.ASCENDING, type: 'Text' };
924+
925+
expect(component.isSortAscending(column)).toBe(null);
926+
});
904927
});
905928
});

projects/ccd-case-ui-toolkit/src/lib/shared/components/search-result/search-result.component.ts

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -387,28 +387,11 @@ export class SearchResultComponent implements OnChanges, OnInit {
387387
}
388388

389389
public isSortAscending(column: SearchResultViewColumn): boolean {
390-
const currentSortOrder = this.currentSortOrder(column);
391-
392-
return currentSortOrder === SortOrder.UNSORTED || currentSortOrder === SortOrder.DESCENDING;
393-
}
394-
395-
private currentSortOrder(column: SearchResultViewColumn): SortOrder {
396-
397-
let isAscending = true;
398-
let isDescending = true;
399-
400-
if (this.comparator(column) === undefined) {
401-
return SortOrder.UNSORTED;
402-
}
403-
for (let i = 0; i < this.resultView.results.length - 1; i++) {
404-
const comparison = this.comparator(column).compare(this.resultView.results[i], this.resultView.results[i + 1]);
405-
isDescending = isDescending && comparison <= 0;
406-
isAscending = isAscending && comparison >= 0;
407-
if (!isAscending && !isDescending) {
408-
break;
409-
}
390+
// simple way to determine if the column param is sorted and if its asc/desc
391+
if (this.consumerSortParameters.column === column.case_field_id) {
392+
return this.consumerSortParameters.order === SortOrder.ASCENDING;
410393
}
411-
return isAscending ? SortOrder.ASCENDING : isDescending ? SortOrder.DESCENDING : SortOrder.UNSORTED;
394+
return null;
412395
}
413396

414397
public getFirstResult(): number {
@@ -457,4 +440,7 @@ export class SearchResultComponent implements OnChanges, OnInit {
457440
}
458441
}
459442
}
443+
444+
// eslint-disable-next-line @typescript-eslint/no-empty-function
445+
noop(): void {}
460446
}

0 commit comments

Comments
 (0)