@@ -62,10 +62,10 @@ function focusCell(cell: ReactScopeMethods): void { |
62 | 62 | } |
63 | 63 | } |
64 | 64 |
|
65 | | -function focusCellByRowIndex(row: ReactScopeMethods, rowIndex: number): void { |
| 65 | +function focusCellByIndex(row: ReactScopeMethods, cellIndex: number): void { |
66 | 66 | const cells = row.getChildren(); |
67 | 67 | if (cells !== null) { |
68 | | - const cell = cells[rowIndex]; |
| 68 | + const cell = cells[cellIndex]; |
69 | 69 | if (cell) { |
70 | 70 | focusCell(cell); |
71 | 71 | } |
@@ -150,31 +150,33 @@ export function createFocusTable(): Array<React.Component> { |
150 | 150 | const currentCell = scopeRef.current; |
151 | 151 | switch (event.key) { |
152 | 152 | case 'ArrowUp': { |
153 | | - const [cells, rowIndex] = getRowCells(currentCell); |
| 153 | + const [cells, cellIndex] = getRowCells(currentCell); |
154 | 154 | if (cells !== null) { |
155 | | - const [columns, columnIndex] = getRows(currentCell); |
156 | | - if (columns !== null) { |
157 | | - if (columnIndex > 0) { |
158 | | - const column = columns[columnIndex - 1]; |
159 | | - focusCellByRowIndex(column, rowIndex); |
160 | | - } else if (columnIndex === 0) { |
| 155 | + const [rows, rowIndex] = getRows(currentCell); |
| 156 | + if (rows !== null) { |
| 157 | + if (rowIndex > 0) { |
| 158 | + const row = rows[rowIndex - 1]; |
| 159 | + focusCellByIndex(row, cellIndex); |
| 160 | + event.preventDefault(); |
| 161 | + } else if (rowIndex === 0) { |
161 | 162 | triggerNavigateOut(currentCell, 'up'); |
162 | 163 | } |
163 | 164 | } |
164 | 165 | } |
165 | 166 | return; |
166 | 167 | } |
167 | 168 | case 'ArrowDown': { |
168 | | - const [cells, rowIndex] = getRowCells(currentCell); |
| 169 | + const [cells, cellIndex] = getRowCells(currentCell); |
169 | 170 | if (cells !== null) { |
170 | | - const [columns, columnIndex] = getRows(currentCell); |
171 | | - if (columns !== null) { |
172 | | - if (columnIndex !== -1) { |
173 | | - if (columnIndex === columns.length - 1) { |
| 171 | + const [rows, rowIndex] = getRows(currentCell); |
| 172 | + if (rows !== null) { |
| 173 | + if (rowIndex !== -1) { |
| 174 | + if (rowIndex === rows.length - 1) { |
174 | 175 | triggerNavigateOut(currentCell, 'down'); |
175 | 176 | } else { |
176 | | - const column = columns[columnIndex + 1]; |
177 | | - focusCellByRowIndex(column, rowIndex); |
| 177 | + const row = rows[rowIndex + 1]; |
| 178 | + focusCellByIndex(row, cellIndex); |
| 179 | + event.preventDefault(); |
178 | 180 | } |
179 | 181 | } |
180 | 182 | } |
@@ -186,6 +188,7 @@ export function createFocusTable(): Array<React.Component> { |
186 | 188 | if (cells !== null) { |
187 | 189 | if (rowIndex > 0) { |
188 | 190 | focusCell(cells[rowIndex - 1]); |
| 191 | + event.preventDefault(); |
189 | 192 | } else if (rowIndex === 0) { |
190 | 193 | triggerNavigateOut(currentCell, 'left'); |
191 | 194 | } |
@@ -200,6 +203,7 @@ export function createFocusTable(): Array<React.Component> { |
200 | 203 | triggerNavigateOut(currentCell, 'right'); |
201 | 204 | } else { |
202 | 205 | focusCell(cells[rowIndex + 1]); |
| 206 | + event.preventDefault(); |
203 | 207 | } |
204 | 208 | } |
205 | 209 | } |
|