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}`,