Skip to content

Commit 70754f1

Browse files
authored
[react-interaction] Tweak Focus Table component (#16862)
1 parent d7f6dd5 commit 70754f1

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

packages/react-interactions/accessibility/src/FocusTable.js

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ function focusCell(cell: ReactScopeMethods): void {
6262
}
6363
}
6464

65-
function focusCellByRowIndex(row: ReactScopeMethods, rowIndex: number): void {
65+
function focusCellByIndex(row: ReactScopeMethods, cellIndex: number): void {
6666
const cells = row.getChildren();
6767
if (cells !== null) {
68-
const cell = cells[rowIndex];
68+
const cell = cells[cellIndex];
6969
if (cell) {
7070
focusCell(cell);
7171
}
@@ -150,31 +150,33 @@ export function createFocusTable(): Array<React.Component> {
150150
const currentCell = scopeRef.current;
151151
switch (event.key) {
152152
case 'ArrowUp': {
153-
const [cells, rowIndex] = getRowCells(currentCell);
153+
const [cells, cellIndex] = getRowCells(currentCell);
154154
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) {
161162
triggerNavigateOut(currentCell, 'up');
162163
}
163164
}
164165
}
165166
return;
166167
}
167168
case 'ArrowDown': {
168-
const [cells, rowIndex] = getRowCells(currentCell);
169+
const [cells, cellIndex] = getRowCells(currentCell);
169170
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) {
174175
triggerNavigateOut(currentCell, 'down');
175176
} else {
176-
const column = columns[columnIndex + 1];
177-
focusCellByRowIndex(column, rowIndex);
177+
const row = rows[rowIndex + 1];
178+
focusCellByIndex(row, cellIndex);
179+
event.preventDefault();
178180
}
179181
}
180182
}
@@ -186,6 +188,7 @@ export function createFocusTable(): Array<React.Component> {
186188
if (cells !== null) {
187189
if (rowIndex > 0) {
188190
focusCell(cells[rowIndex - 1]);
191+
event.preventDefault();
189192
} else if (rowIndex === 0) {
190193
triggerNavigateOut(currentCell, 'left');
191194
}
@@ -200,6 +203,7 @@ export function createFocusTable(): Array<React.Component> {
200203
triggerNavigateOut(currentCell, 'right');
201204
} else {
202205
focusCell(cells[rowIndex + 1]);
206+
event.preventDefault();
203207
}
204208
}
205209
}

packages/react-reconciler/src/ReactFiber.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,7 @@ function createFiberFromScope(
789789
) {
790790
const fiber = createFiber(ScopeComponent, pendingProps, key, mode);
791791
fiber.type = scope;
792+
fiber.elementType = scope;
792793
fiber.expirationTime = expirationTime;
793794
return fiber;
794795
}

0 commit comments

Comments
 (0)