From 7fea00fc347a23b856a0924b43ea94c8a553a3ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=B3=E5=BB=B7=E5=AE=89?= <73953029+nrps9909@users.noreply.github.com> Date: Thu, 27 Aug 2026 16:30:03 +0800 Subject: [PATCH] fix: omit inert row click handlers --- src/hooks/useRowInfo.tsx | 15 +++++++++------ tests/Table.spec.jsx | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/hooks/useRowInfo.tsx b/src/hooks/useRowInfo.tsx index cdba4059e..bd02566e8 100644 --- a/src/hooks/useRowInfo.tsx +++ b/src/hooks/useRowInfo.tsx @@ -87,13 +87,16 @@ export default function useRowInfo( const rowProps = onRow?.(record, recordIndex); const onRowClick = rowProps?.onClick; - const onClick: React.MouseEventHandler = (event, ...args) => { - if (expandRowByClick && mergedExpandable) { - onTriggerExpand(record, event); - } + const onClick: React.MouseEventHandler = + onRowClick || (expandRowByClick && mergedExpandable) + ? (event, ...args) => { + if (expandRowByClick && mergedExpandable) { + onTriggerExpand(record, event); + } - onRowClick?.(event, ...args); - }; + onRowClick?.(event, ...args); + } + : undefined; // ====================== RowClassName ====================== let computeRowClassName: string; diff --git a/tests/Table.spec.jsx b/tests/Table.spec.jsx index a4d1a74c1..a199837d9 100644 --- a/tests/Table.spec.jsx +++ b/tests/Table.spec.jsx @@ -503,6 +503,25 @@ describe('Table.Basic', () => { }); describe('onRow', () => { + it('does not attach an inert click handler by default', () => { + const rowProps = []; + const Row = props => { + rowProps.push(props); + return ; + }; + + render( + createTable({ + components: { body: { row: Row } }, + }), + ); + + expect(rowProps).not.toHaveLength(0); + rowProps.forEach(props => { + expect(props.onClick).toBeUndefined(); + }); + }); + it('renders onRow correctly', () => { const onRow = (record, index) => ({ id: `row-${record.key}`,