Skip to content

Commit 65e2de1

Browse files
authored
fix: Table onRow not refresh Table (#459)
1 parent 3371d21 commit 65e2de1

File tree

2 files changed

+40
-8
lines changed

2 files changed

+40
-8
lines changed

src/Body/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ function Body<RecordType>({
110110
}, [
111111
data,
112112
prefixCls,
113+
onRow,
113114
measureColumnWidth,
114115
stickyOffsets,
115116
expandedKeys,

tests/Table.spec.js

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -458,16 +458,47 @@ describe('Table.Basic', () => {
458458
expect(wrapper.find('tbody tr').length).toBeTruthy();
459459
});
460460

461-
it('renders onRow correctly', () => {
462-
const onRow = (record, index) => ({
463-
id: `row-${record.key}`,
464-
index,
461+
describe('onRow', () => {
462+
it('renders onRow correctly', () => {
463+
const onRow = (record, index) => ({
464+
id: `row-${record.key}`,
465+
index,
466+
});
467+
const wrapper = mount(createTable({ onRow }));
468+
469+
expect(wrapper.find('tbody tr').length).toBeTruthy();
470+
wrapper.find('tbody tr').forEach((tr, index) => {
471+
expect(tr.props().id).toEqual(`row-${data[index].key}`);
472+
});
465473
});
466-
const wrapper = mount(createTable({ onRow }));
467474

468-
expect(wrapper.find('tbody tr').length).toBeTruthy();
469-
wrapper.find('tbody tr').forEach((tr, index) => {
470-
expect(tr.props().id).toEqual(`row-${data[index].key}`);
475+
it('onRow should keep update', () => {
476+
const Test = () => {
477+
const [count, setCount] = React.useState(0);
478+
479+
return (
480+
<div>
481+
<Table
482+
columns={[{ dataIndex: 'key' }]}
483+
data={[{ key: 0 }]}
484+
onRow={() => ({
485+
onClick() {
486+
setCount(count + 1);
487+
},
488+
})}
489+
/>
490+
<span id="count">{count}</span>
491+
</div>
492+
);
493+
};
494+
const wrapper = mount(<Test />);
495+
for (let i = 0; i < 10; i += 1) {
496+
wrapper
497+
.find('tbody tr td')
498+
.last()
499+
.simulate('click');
500+
expect(wrapper.find('#count').text()).toEqual(String(i + 1));
501+
}
471502
});
472503
});
473504

0 commit comments

Comments
 (0)