Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/hooks/useRowInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,16 @@ export default function useRowInfo<RecordType>(
const rowProps = onRow?.(record, recordIndex);
const onRowClick = rowProps?.onClick;

const onClick: React.MouseEventHandler<HTMLElement> = (event, ...args) => {
if (expandRowByClick && mergedExpandable) {
onTriggerExpand(record, event);
}
const onClick: React.MouseEventHandler<HTMLElement> =
onRowClick || (expandRowByClick && mergedExpandable)
? (event, ...args) => {
if (expandRowByClick && mergedExpandable) {
onTriggerExpand(record, event);
}

onRowClick?.(event, ...args);
};
onRowClick?.(event, ...args);
}
: undefined;

// ====================== RowClassName ======================
let computeRowClassName: string;
Expand Down
19 changes: 19 additions & 0 deletions tests/Table.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 <tr {...props} />;
};

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