Skip to content

Commit b43c056

Browse files
authored
fix: Table row missing data-row-key (#405)
* body add missing data-row-key * update test case
1 parent 80523b5 commit b43c056

File tree

6 files changed

+66
-0
lines changed

6 files changed

+66
-0
lines changed

src/Body/BodyRow.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export interface BodyRowProps<RecordType> {
3232
onRow: GetComponentProps<RecordType>;
3333
rowExpandable: (record: RecordType) => boolean;
3434
indent?: number;
35+
rowKey: React.Key;
3536
getRowKey: GetRowKey<RecordType>;
3637
childrenColumnName: string;
3738
}
@@ -43,6 +44,7 @@ function BodyRow<RecordType extends { children?: RecordType[] }>(props: BodyRowP
4344
stickyOffsets,
4445
record,
4546
index,
47+
rowKey,
4648
getRowKey,
4749
rowExpandable,
4850
onRow,
@@ -118,6 +120,7 @@ function BodyRow<RecordType extends { children?: RecordType[] }>(props: BodyRowP
118120
const baseRowNode = (
119121
<RowComponent
120122
{...additionalProps}
123+
data-row-key={rowKey}
121124
className={classNames(
122125
className,
123126
`${prefixCls}-row`,

src/Body/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ function Body<RecordType>({
4444
return [
4545
<BodyRow
4646
key={key}
47+
rowKey={key}
4748
record={record}
4849
recordKey={key}
4950
index={index}

tests/Table.spec.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,4 +729,21 @@ describe('Table.Basic', () => {
729729
);
730730
expect(wrapper.find('.test')).toHaveLength(1);
731731
});
732+
733+
it('component body should pass `data-row-key`', () => {
734+
const wrapper = mount(
735+
<Table
736+
columns={[{ dataIndex: 'test' }]}
737+
components={{ body: { row: props => <tr {...props} /> } }}
738+
data={[{ test: 'bamboo', key: 'light' }]}
739+
/>,
740+
);
741+
742+
expect(
743+
wrapper
744+
.find('tr')
745+
.last()
746+
.props()['data-row-key'],
747+
).toEqual('light');
748+
});
732749
});

tests/__snapshots__/ExpandRow.spec.js.snap

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ exports[`Table.Expand childrenColumnName 1`] = `
3636
>
3737
<tr
3838
class="rc-table-row rc-table-row-level-0"
39+
data-row-key="0"
3940
>
4041
<td
4142
class="rc-table-cell rc-table-cell-with-append"
@@ -56,6 +57,7 @@ exports[`Table.Expand childrenColumnName 1`] = `
5657
</tr>
5758
<tr
5859
class="rc-table-row rc-table-row-level-1"
60+
data-row-key="0"
5961
>
6062
<td
6163
class="rc-table-cell rc-table-cell-with-append"
@@ -76,6 +78,7 @@ exports[`Table.Expand childrenColumnName 1`] = `
7678
</tr>
7779
<tr
7880
class="rc-table-row rc-table-row-level-0"
81+
data-row-key="1"
7982
>
8083
<td
8184
class="rc-table-cell rc-table-cell-with-append"
@@ -153,6 +156,7 @@ exports[`Table.Expand renders fixed column correctly work 1`] = `
153156
>
154157
<tr
155158
class="rc-table-row rc-table-row-level-0"
159+
data-row-key="0"
156160
>
157161
<td
158162
class="rc-table-cell rc-table-row-expand-icon-cell rc-table-cell-fix-left"
@@ -199,6 +203,7 @@ exports[`Table.Expand renders fixed column correctly work 1`] = `
199203
</tr>
200204
<tr
201205
class="rc-table-row rc-table-row-level-0"
206+
data-row-key="1"
202207
>
203208
<td
204209
class="rc-table-cell rc-table-row-expand-icon-cell rc-table-cell-fix-left"
@@ -286,6 +291,7 @@ exports[`Table.Expand renders tree row correctly 1`] = `
286291
>
287292
<tr
288293
class="rc-table-row rc-table-row-level-0"
294+
data-row-key="0"
289295
>
290296
<td
291297
class="rc-table-cell rc-table-cell-with-append"
@@ -306,6 +312,7 @@ exports[`Table.Expand renders tree row correctly 1`] = `
306312
</tr>
307313
<tr
308314
class="rc-table-row rc-table-row-level-1"
315+
data-row-key="0"
309316
>
310317
<td
311318
class="rc-table-cell rc-table-cell-with-append"
@@ -326,6 +333,7 @@ exports[`Table.Expand renders tree row correctly 1`] = `
326333
</tr>
327334
<tr
328335
class="rc-table-row rc-table-row-level-0"
336+
data-row-key="1"
329337
>
330338
<td
331339
class="rc-table-cell rc-table-cell-with-append"
@@ -387,6 +395,7 @@ exports[`Table.Expand renders tree row correctly with different children 1`] = `
387395
>
388396
<tr
389397
class="rc-table-row rc-table-row-level-0"
398+
data-row-key="0"
390399
>
391400
<td
392401
class="rc-table-cell rc-table-cell-with-append"
@@ -407,6 +416,7 @@ exports[`Table.Expand renders tree row correctly with different children 1`] = `
407416
</tr>
408417
<tr
409418
class="rc-table-row rc-table-row-level-0"
419+
data-row-key="1"
410420
>
411421
<td
412422
class="rc-table-cell rc-table-cell-with-append"
@@ -427,6 +437,7 @@ exports[`Table.Expand renders tree row correctly with different children 1`] = `
427437
</tr>
428438
<tr
429439
class="rc-table-row rc-table-row-level-0"
440+
data-row-key="2"
430441
>
431442
<td
432443
class="rc-table-cell rc-table-cell-with-append"
@@ -447,6 +458,7 @@ exports[`Table.Expand renders tree row correctly with different children 1`] = `
447458
</tr>
448459
<tr
449460
class="rc-table-row rc-table-row-level-0"
461+
data-row-key="3"
450462
>
451463
<td
452464
class="rc-table-cell rc-table-cell-with-append"
@@ -467,6 +479,7 @@ exports[`Table.Expand renders tree row correctly with different children 1`] = `
467479
</tr>
468480
<tr
469481
class="rc-table-row rc-table-row-level-0"
482+
data-row-key="4"
470483
>
471484
<td
472485
class="rc-table-cell rc-table-cell-with-append"
@@ -487,6 +500,7 @@ exports[`Table.Expand renders tree row correctly with different children 1`] = `
487500
</tr>
488501
<tr
489502
class="rc-table-row rc-table-row-level-0"
503+
data-row-key="5"
490504
>
491505
<td
492506
class="rc-table-cell rc-table-cell-with-append"

tests/__snapshots__/FixedColumn.spec.js.snap

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ exports[`Table.FixedColumn renders correctly scrollX - with data 1`] = `
106106
>
107107
<tr
108108
class="rc-table-row rc-table-row-level-0"
109+
data-row-key="1"
109110
>
110111
<td
111112
class="rc-table-cell rc-table-cell-fix-left"
@@ -171,6 +172,7 @@ exports[`Table.FixedColumn renders correctly scrollX - with data 1`] = `
171172
</tr>
172173
<tr
173174
class="rc-table-row rc-table-row-level-0"
175+
data-row-key="2"
174176
>
175177
<td
176178
class="rc-table-cell rc-table-cell-fix-left"
@@ -236,6 +238,7 @@ exports[`Table.FixedColumn renders correctly scrollX - with data 1`] = `
236238
</tr>
237239
<tr
238240
class="rc-table-row rc-table-row-level-0"
241+
data-row-key="3"
239242
>
240243
<td
241244
class="rc-table-cell rc-table-cell-fix-left"
@@ -283,6 +286,7 @@ exports[`Table.FixedColumn renders correctly scrollX - with data 1`] = `
283286
</tr>
284287
<tr
285288
class="rc-table-row rc-table-row-level-0"
289+
data-row-key="4"
286290
>
287291
<td
288292
class="rc-table-cell rc-table-cell-fix-left"
@@ -330,6 +334,7 @@ exports[`Table.FixedColumn renders correctly scrollX - with data 1`] = `
330334
</tr>
331335
<tr
332336
class="rc-table-row rc-table-row-level-0"
337+
data-row-key="5"
333338
>
334339
<td
335340
class="rc-table-cell rc-table-cell-fix-left"
@@ -377,6 +382,7 @@ exports[`Table.FixedColumn renders correctly scrollX - with data 1`] = `
377382
</tr>
378383
<tr
379384
class="rc-table-row rc-table-row-level-0"
385+
data-row-key="6"
380386
>
381387
<td
382388
class="rc-table-cell rc-table-cell-fix-left"
@@ -424,6 +430,7 @@ exports[`Table.FixedColumn renders correctly scrollX - with data 1`] = `
424430
</tr>
425431
<tr
426432
class="rc-table-row rc-table-row-level-0"
433+
data-row-key="7"
427434
>
428435
<td
429436
class="rc-table-cell rc-table-cell-fix-left"
@@ -471,6 +478,7 @@ exports[`Table.FixedColumn renders correctly scrollX - with data 1`] = `
471478
</tr>
472479
<tr
473480
class="rc-table-row rc-table-row-level-0"
481+
data-row-key="8"
474482
>
475483
<td
476484
class="rc-table-cell rc-table-cell-fix-left"
@@ -518,6 +526,7 @@ exports[`Table.FixedColumn renders correctly scrollX - with data 1`] = `
518526
</tr>
519527
<tr
520528
class="rc-table-row rc-table-row-level-0"
529+
data-row-key="9"
521530
>
522531
<td
523532
class="rc-table-cell rc-table-cell-fix-left"
@@ -834,6 +843,7 @@ exports[`Table.FixedColumn renders correctly scrollXY - with data 1`] = `
834843
>
835844
<tr
836845
class="rc-table-row rc-table-row-level-0"
846+
data-row-key="1"
837847
>
838848
<td
839849
class="rc-table-cell rc-table-cell-fix-left"
@@ -899,6 +909,7 @@ exports[`Table.FixedColumn renders correctly scrollXY - with data 1`] = `
899909
</tr>
900910
<tr
901911
class="rc-table-row rc-table-row-level-0"
912+
data-row-key="2"
902913
>
903914
<td
904915
class="rc-table-cell rc-table-cell-fix-left"
@@ -964,6 +975,7 @@ exports[`Table.FixedColumn renders correctly scrollXY - with data 1`] = `
964975
</tr>
965976
<tr
966977
class="rc-table-row rc-table-row-level-0"
978+
data-row-key="3"
967979
>
968980
<td
969981
class="rc-table-cell rc-table-cell-fix-left"
@@ -1011,6 +1023,7 @@ exports[`Table.FixedColumn renders correctly scrollXY - with data 1`] = `
10111023
</tr>
10121024
<tr
10131025
class="rc-table-row rc-table-row-level-0"
1026+
data-row-key="4"
10141027
>
10151028
<td
10161029
class="rc-table-cell rc-table-cell-fix-left"
@@ -1058,6 +1071,7 @@ exports[`Table.FixedColumn renders correctly scrollXY - with data 1`] = `
10581071
</tr>
10591072
<tr
10601073
class="rc-table-row rc-table-row-level-0"
1074+
data-row-key="5"
10611075
>
10621076
<td
10631077
class="rc-table-cell rc-table-cell-fix-left"
@@ -1105,6 +1119,7 @@ exports[`Table.FixedColumn renders correctly scrollXY - with data 1`] = `
11051119
</tr>
11061120
<tr
11071121
class="rc-table-row rc-table-row-level-0"
1122+
data-row-key="6"
11081123
>
11091124
<td
11101125
class="rc-table-cell rc-table-cell-fix-left"
@@ -1152,6 +1167,7 @@ exports[`Table.FixedColumn renders correctly scrollXY - with data 1`] = `
11521167
</tr>
11531168
<tr
11541169
class="rc-table-row rc-table-row-level-0"
1170+
data-row-key="7"
11551171
>
11561172
<td
11571173
class="rc-table-cell rc-table-cell-fix-left"
@@ -1199,6 +1215,7 @@ exports[`Table.FixedColumn renders correctly scrollXY - with data 1`] = `
11991215
</tr>
12001216
<tr
12011217
class="rc-table-row rc-table-row-level-0"
1218+
data-row-key="8"
12021219
>
12031220
<td
12041221
class="rc-table-cell rc-table-cell-fix-left"
@@ -1246,6 +1263,7 @@ exports[`Table.FixedColumn renders correctly scrollXY - with data 1`] = `
12461263
</tr>
12471264
<tr
12481265
class="rc-table-row rc-table-row-level-0"
1266+
data-row-key="9"
12491267
>
12501268
<td
12511269
class="rc-table-cell rc-table-cell-fix-left"

0 commit comments

Comments
 (0)