🐛 fix(data-grid): 行号点击支持取消行选择 (#910)

Fixes #910
This commit is contained in:
AutumnNazi
2026-08-11 15:30:56 +08:00
parent baccc6b85d
commit 1781dbda57
2 changed files with 12 additions and 2 deletions

View File

@@ -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();
});

View File

@@ -3381,7 +3381,9 @@ const DataGrid: React.FC<DataGridProps> = ({
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) => {