From 1781dbda5729d9bbb685e03dd2a9fd9e62ade85f Mon Sep 17 00:00:00 2001 From: AutumnNazi <104422820+AutumnNazi@users.noreply.github.com> Date: Tue, 11 Aug 2026 15:30:56 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(data-grid):=20=E8=A1=8C?= =?UTF-8?q?=E5=8F=B7=E7=82=B9=E5=87=BB=E6=94=AF=E6=8C=81=E5=8F=96=E6=B6=88?= =?UTF-8?q?=E8=A1=8C=E9=80=89=E6=8B=A9=20(#910)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #910 --- frontend/src/components/DataGrid.ddl.test.tsx | 10 +++++++++- frontend/src/components/DataGrid.tsx | 4 +++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/frontend/src/components/DataGrid.ddl.test.tsx b/frontend/src/components/DataGrid.ddl.test.tsx index 8cb87ea9..ac2a5e7f 100644 --- a/frontend/src/components/DataGrid.ddl.test.tsx +++ b/frontend/src/components/DataGrid.ddl.test.tsx @@ -1073,7 +1073,7 @@ describe('DataGrid DDL interactions', () => { vi.unstubAllGlobals(); }); - it('selects one row when its row number cell is clicked', async () => { + it('toggles one row when its row number cell is clicked', async () => { storeState.appearance.uiVersion = 'v2'; const rows = [ { [GONAVI_ROW_KEY]: 'row-1', id: 1 }, @@ -1107,6 +1107,14 @@ describe('DataGrid DDL interactions', () => { expect(stopPropagation).toHaveBeenCalledTimes(1); expect(testRenderState.latestTableProps.rowHoverable).toBe(false); expect(testRenderState.latestTableProps.rowSelection.selectedRowKeys).toEqual(['row-2']); + + await act(async () => { + rowNumberColumn.onCell(rows[1], 1).onClick({ stopPropagation }); + }); + await waitForEffects(); + + expect(stopPropagation).toHaveBeenCalledTimes(2); + expect(testRenderState.latestTableProps.rowSelection.selectedRowKeys).toEqual([]); renderer!.unmount(); }); diff --git a/frontend/src/components/DataGrid.tsx b/frontend/src/components/DataGrid.tsx index 0f4d203c..03cda76f 100644 --- a/frontend/src/components/DataGrid.tsx +++ b/frontend/src/components/DataGrid.tsx @@ -3381,7 +3381,9 @@ const DataGrid: React.FC = ({ const handleRowNumberClick = useCallback((record: Item) => { const key = record?.[GONAVI_ROW_KEY]; if (key === undefined || key === null) return; - setSelectedRowKeys([key]); + setSelectedRowKeys((previousKeys) => ( + previousKeys.length === 1 && previousKeys[0] === key ? [] : [key] + )); }, []); const handleRowNumberDoubleClick = useCallback((index: number) => {