@@ -336,4 +336,139 @@ describe('Table.FixedColumn', () => {
336
336
expect ( container . querySelector ( '.rc-table' ) ) . toHaveClass ( 'rc-table-fix-start-shadow-show' ) ;
337
337
expect ( container . querySelector ( '.rc-table' ) ) . toHaveClass ( 'rc-table-fix-end-shadow-show' ) ;
338
338
} ) ;
339
+
340
+ describe ( 'colSpan=0 with fixed columns regression test' , ( ) => {
341
+ interface TestDataType {
342
+ key : string ;
343
+ col0 : string ;
344
+ col1 : string ;
345
+ col2 : string ;
346
+ }
347
+
348
+ const testColumns : ColumnsType < TestDataType > = [
349
+ {
350
+ title : 'Column 0' ,
351
+ dataIndex : 'col0' ,
352
+ key : 'col0' ,
353
+ width : 100 ,
354
+ fixed : 'left' ,
355
+ onCell : ( record , index ) => {
356
+ if ( index === 1 ) {
357
+ return { colSpan : 0 } ;
358
+ }
359
+ return { } ;
360
+ } ,
361
+ } ,
362
+ {
363
+ title : 'Column 1' ,
364
+ dataIndex : 'col1' ,
365
+ key : 'col1' ,
366
+ width : 120 ,
367
+ fixed : 'left' ,
368
+ onCell : ( record , index ) => {
369
+ if ( index === 1 ) {
370
+ return { colSpan : 2 } ;
371
+ }
372
+ return { } ;
373
+ } ,
374
+ } ,
375
+ {
376
+ title : 'Column 2' ,
377
+ dataIndex : 'col2' ,
378
+ key : 'col2' ,
379
+ width : 150 ,
380
+ } ,
381
+ ] ;
382
+
383
+ const testData : TestDataType [ ] = [
384
+ { key : '0' , col0 : 'Row0-Col0' , col1 : 'Row0-Col1' , col2 : 'Row0-Col2' } ,
385
+ { key : '1' , col0 : 'Row1-Col0' , col1 : 'Row1-Merged' , col2 : 'Row1-Col2' } ,
386
+ { key : '2' , col0 : 'Row2-Col0' , col1 : 'Row2-Col1' , col2 : 'Row2-Col2' } ,
387
+ ] ;
388
+
389
+ it ( 'should calculate correct sticky offsets when colSpan=0 exists' , async ( ) => {
390
+ const { container } = render (
391
+ < Table columns = { testColumns } data = { testData } scroll = { { x : 500 } } /> ,
392
+ ) ;
393
+
394
+ await triggerResize ( container . querySelector < HTMLElement > ( '.rc-table' ) ) ;
395
+
396
+ act ( ( ) => {
397
+ const coll = container . querySelector ( '.rc-table-resize-collection' ) ;
398
+ if ( coll ) {
399
+ triggerResize ( coll as HTMLElement ) ;
400
+ }
401
+ } ) ;
402
+
403
+ await act ( async ( ) => {
404
+ vi . runAllTimers ( ) ;
405
+ await Promise . resolve ( ) ;
406
+ } ) ;
407
+
408
+ const rows = container . querySelectorAll ( '.rc-table-tbody .rc-table-row' ) ;
409
+ expect ( rows ) . toHaveLength ( 3 ) ;
410
+
411
+ const secondRow = rows [ 1 ] ;
412
+ const cells = secondRow . querySelectorAll ( '.rc-table-cell' ) ;
413
+ expect ( cells ) . toHaveLength ( 2 ) ;
414
+
415
+ const mergedCell = cells [ 0 ] ;
416
+ expect ( mergedCell ) . toHaveAttribute ( 'colSpan' , '2' ) ;
417
+
418
+ expect ( mergedCell . textContent ) . toContain ( 'Row1-Merged' ) ;
419
+ const hasFixedLeftClass = mergedCell . classList . contains ( 'rc-table-cell-fix-left' ) ;
420
+
421
+ if ( hasFixedLeftClass ) {
422
+ const cellStyle = window . getComputedStyle ( mergedCell ) ;
423
+ expect ( cellStyle . left ) . toBe ( '0px' ) ;
424
+ }
425
+ } ) ;
426
+
427
+ it ( 'should work correctly with expandable rows' , async ( ) => {
428
+ const expandableTestData = testData . map ( item => ( {
429
+ ...item ,
430
+ children :
431
+ item . key === '1'
432
+ ? [ { key : '1-0' , col0 : 'Child-Col0' , col1 : 'Child-Col1' , col2 : 'Child-Col2' } ]
433
+ : undefined ,
434
+ } ) ) ;
435
+
436
+ const { container } = render (
437
+ < Table
438
+ columns = { testColumns }
439
+ data = { expandableTestData }
440
+ scroll = { { x : 500 } }
441
+ expandable = { {
442
+ expandedRowKeys : [ '1' ] ,
443
+ expandRowByClick : true ,
444
+ } }
445
+ /> ,
446
+ ) ;
447
+
448
+ await triggerResize ( container . querySelector < HTMLElement > ( '.rc-table' ) ) ;
449
+
450
+ act ( ( ) => {
451
+ const coll = container . querySelector ( '.rc-table-resize-collection' ) ;
452
+ if ( coll ) {
453
+ triggerResize ( coll as HTMLElement ) ;
454
+ }
455
+ } ) ;
456
+
457
+ await act ( async ( ) => {
458
+ vi . runAllTimers ( ) ;
459
+ await Promise . resolve ( ) ;
460
+ } ) ;
461
+
462
+ const allRows = container . querySelectorAll ( '.rc-table-tbody .rc-table-row' ) ;
463
+ expect ( allRows . length ) . toBeGreaterThan ( 3 ) ; // 包含展开的子行
464
+
465
+ const parentRow = allRows [ 1 ] ;
466
+ const parentCells = parentRow . querySelectorAll ( '.rc-table-cell' ) ;
467
+ expect ( parentCells ) . toHaveLength ( 2 ) ;
468
+
469
+ const childRow = allRows [ 2 ] ;
470
+ const childCells = childRow . querySelectorAll ( '.rc-table-cell' ) ;
471
+ expect ( childCells ) . toHaveLength ( 3 ) ;
472
+ } ) ;
473
+ } ) ;
339
474
} ) ;
0 commit comments