From a2796822949e4200d5e46c46d2cd608502f55efe Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Mon, 5 Oct 2026 00:12:47 +0100 Subject: [PATCH] TreeDataGrid: focus the parent row on ArrowLeft Pressing ArrowLeft on a collapsed child group made the parent group row active without moving focus to it, leaving focus on the child row. Also fix two comments that described the select/unselect branches the wrong way round. Co-Authored-By: Claude Opus 5.5 (1M context) --- src/TreeDataGrid.tsx | 6 +++--- test/browser/TreeDataGrid.test.tsx | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/TreeDataGrid.tsx b/src/TreeDataGrid.tsx index 8f9a85d639..d88bad6b18 100644 --- a/src/TreeDataGrid.tsx +++ b/src/TreeDataGrid.tsx @@ -273,7 +273,7 @@ export function TreeDataGrid({ const key = rowKeyGetter(row); if (selectedRows?.has(key) && !newSelectedRows.has(key)) { if (isGroupRow(row)) { - // select all children if the parent row is selected + // unselect all children if the parent row is unselected for (const cr of row.childRows) { newRawSelectedRows.delete(rawRowKeyGetter(cr)); } @@ -282,7 +282,7 @@ export function TreeDataGrid({ } } else if (!selectedRows?.has(key) && newSelectedRows.has(key)) { if (isGroupRow(row)) { - // unselect all children if the parent row is unselected + // select all children if the parent row is selected for (const cr of row.childRows) { newRawSelectedRows.add(rawRowKeyGetter(cr)); } @@ -323,7 +323,7 @@ export function TreeDataGrid({ const parentRowAndIndex = getParentRowAndIndex(row); if (parentRowAndIndex !== undefined) { event.preventGridDefault(); - setActivePosition({ idx, rowIdx: parentRowAndIndex[1] }); + setActivePosition({ idx, rowIdx: parentRowAndIndex[1] }, { shouldFocus: true }); } } } diff --git a/test/browser/TreeDataGrid.test.tsx b/test/browser/TreeDataGrid.test.tsx index 8c825013a9..e8be78a270 100644 --- a/test/browser/TreeDataGrid.test.tsx +++ b/test/browser/TreeDataGrid.test.tsx @@ -397,6 +397,7 @@ test('cell navigation in a treegrid', async () => { await expect.element(rows.nth(1)).not.toHaveClass(rowActiveClassname); await userEvent.keyboard('{arrowleft}{arrowleft}'); await expect.element(rows.nth(1)).toHaveClass(rowActiveClassname); + await expect.element(rows.nth(1)).toHaveFocus(); await userEvent.keyboard('{end}'); await expect.element(rows.nth(5)).toHaveClass(rowActiveClassname);