Skip to content

Commit d9d1f98

Browse files
guifryaaronfowles
authored andcommitted
fix: accessibility - prevent the first text grid cell from being selected when tabbing
1 parent b450ddc commit d9d1f98

2 files changed

Lines changed: 19 additions & 29 deletions

File tree

src/frontend/view/customURLCellRenderer.ts

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,35 +18,6 @@ export class URLCellRenderer {
1818
this.eGui.innerHTML = `<a class="govuk-link" key=${this.getUniqueKey()} href="${
1919
params.value
2020
}">${params.value}</a>`
21-
this.registerEventsListeners()
22-
}
23-
24-
registerEventsListeners() {
25-
document.addEventListener('keydown', (event) => {
26-
if (
27-
!['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'Tab'].includes(
28-
event.key
29-
)
30-
) {
31-
return
32-
}
33-
const {
34-
colDef: { field },
35-
rowIndex,
36-
} = this.params
37-
const focusedCell = this.params.api.getFocusedCell()
38-
if (
39-
focusedCell?.column.getColId() === field &&
40-
focusedCell?.rowIndex === rowIndex
41-
) {
42-
const innerLink = document.querySelector(
43-
`a[key="${this.getUniqueKey()}"]`
44-
)
45-
if (innerLink instanceof HTMLElement) {
46-
innerLink.focus()
47-
}
48-
}
49-
})
5021
}
5122

5223
getUniqueKey = () => {

src/frontend/view/view-grid.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,28 @@ const createAgGrid = () => {
7575
...(sortConfig[field] || {}),
7676
}))
7777

78+
const suppressKeyboardEvent = (
79+
params: SuppressKeyboardEventParams
80+
): boolean => {
81+
return params.event.key.toUpperCase() === 'TAB'
82+
}
83+
84+
const suppressHeaderKeyboardEvent = (params): boolean => {
85+
const colNames = gridOptions.columnApi
86+
.getAllDisplayedColumns()
87+
.map((col) => col.colId)
88+
const lastCol = colNames[colNames.length - 1]
89+
90+
return params.event.key.toUpperCase() === 'TAB' && params.column.getId() === lastCol
91+
}
92+
7893
const gridOptions = {
7994
rowData,
8095
columnDefs,
96+
defaultColDef: {
97+
suppressKeyboardEvent,
98+
suppressHeaderKeyboardEvent,
99+
},
81100
onPaginationChanged: function () {
82101
viewPagination(gridOptions)
83102
},

0 commit comments

Comments
 (0)