Skip to content

Commit 7fea00f

Browse files
committed
fix: omit inert row click handlers
1 parent 7977f2b commit 7fea00f

2 files changed

Lines changed: 28 additions & 6 deletions

File tree

src/hooks/useRowInfo.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,16 @@ export default function useRowInfo<RecordType>(
8787
const rowProps = onRow?.(record, recordIndex);
8888
const onRowClick = rowProps?.onClick;
8989

90-
const onClick: React.MouseEventHandler<HTMLElement> = (event, ...args) => {
91-
if (expandRowByClick && mergedExpandable) {
92-
onTriggerExpand(record, event);
93-
}
90+
const onClick: React.MouseEventHandler<HTMLElement> =
91+
onRowClick || (expandRowByClick && mergedExpandable)
92+
? (event, ...args) => {
93+
if (expandRowByClick && mergedExpandable) {
94+
onTriggerExpand(record, event);
95+
}
9496

95-
onRowClick?.(event, ...args);
96-
};
97+
onRowClick?.(event, ...args);
98+
}
99+
: undefined;
97100

98101
// ====================== RowClassName ======================
99102
let computeRowClassName: string;

tests/Table.spec.jsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,25 @@ describe('Table.Basic', () => {
503503
});
504504

505505
describe('onRow', () => {
506+
it('does not attach an inert click handler by default', () => {
507+
const rowProps = [];
508+
const Row = props => {
509+
rowProps.push(props);
510+
return <tr {...props} />;
511+
};
512+
513+
render(
514+
createTable({
515+
components: { body: { row: Row } },
516+
}),
517+
);
518+
519+
expect(rowProps).not.toHaveLength(0);
520+
rowProps.forEach(props => {
521+
expect(props.onClick).toBeUndefined();
522+
});
523+
});
524+
506525
it('renders onRow correctly', () => {
507526
const onRow = (record, index) => ({
508527
id: `row-${record.key}`,

0 commit comments

Comments
 (0)