@@ -30,7 +30,7 @@ import { PrimaryColor } from "constants/style";
30
30
import { trans } from "i18n" ;
31
31
import _ , { isEqual } from "lodash" ;
32
32
import { darkenColor , isDarkColor , isValidColor , ScrollBar } from "lowcoder-design" ;
33
- import React , { Children , useCallback , useContext , useEffect , useMemo , useRef , useState } from "react" ;
33
+ import React , { Children , useCallback , useContext , useEffect , useImperativeHandle , useMemo , useRef , useState } from "react" ;
34
34
import { Resizable } from "react-resizable" ;
35
35
import styled , { css } from "styled-components" ;
36
36
import { useMergeCompStyles , useUserViewMode } from "util/hooks" ;
@@ -498,10 +498,10 @@ const TableTdLoading = styled(Skeleton.Button)<SkeletonButtonProps & {
498
498
}
499
499
` ;
500
500
501
- const ResizeableTitle = ( props : any ) => {
501
+ const ResizeableTitle = React . forwardRef < HTMLTableHeaderCellElement , any > ( ( props , ref ) => {
502
502
const { onResize, onResizeStop, width, viewModeResizable, ...restProps } = props ;
503
503
const [ childWidth , setChildWidth ] = useState ( 0 ) ;
504
- const resizeRef = useRef < HTMLDivElement > ( null ) ;
504
+ const resizeRef = useRef < HTMLTableHeaderCellElement > ( null ) ;
505
505
const isUserViewMode = useUserViewMode ( ) ;
506
506
507
507
const updateChildWidth = useCallback ( ( ) => {
@@ -526,6 +526,8 @@ const ResizeableTitle = (props: any) => {
526
526
} ;
527
527
} , [ updateChildWidth ] ) ;
528
528
529
+ useImperativeHandle ( ref , ( ) => resizeRef . current ! , [ ] ) ;
530
+
529
531
const isNotDataColumn = _ . isNil ( restProps . title ) ;
530
532
if ( ( isUserViewMode && ! restProps . viewModeResizable ) || isNotDataColumn ) {
531
533
return < TableTh ref = { resizeRef } { ...restProps } width = { width } /> ;
@@ -559,7 +561,7 @@ const ResizeableTitle = (props: any) => {
559
561
< TableTh ref = { resizeRef } { ...restProps } title = "" />
560
562
</ Resizable >
561
563
) ;
562
- } ;
564
+ } ) ;
563
565
564
566
type CustomTableProps < RecordType > = Omit < TableProps < RecordType > , "components" | "columns" > & {
565
567
columns : CustomColumnType < RecordType > [ ] ;
@@ -579,7 +581,7 @@ type CustomTableProps<RecordType> = Omit<TableProps<RecordType>, "components" |
579
581
} ;
580
582
} ;
581
583
582
- const TableCellView = React . memo ( ( props : {
584
+ const TableCellView = React . forwardRef < HTMLTableCellElement , {
583
585
record : RecordType ;
584
586
title : string ;
585
587
rowColorFn : RowColorViewType ;
@@ -594,7 +596,7 @@ const TableCellView = React.memo((props: {
594
596
autoHeight ?: boolean ;
595
597
loading ?: boolean ;
596
598
customAlign ?: 'left' | 'center' | 'right' ;
597
- } ) => {
599
+ } > ( ( props , ref ) => {
598
600
const {
599
601
record,
600
602
title,
@@ -651,17 +653,23 @@ const TableCellView = React.memo((props: {
651
653
} ;
652
654
} , [ record , rowIndex , title , rowColorFn , rowHeightFn , cellColorFn , columnStyle , columnsStyle ] ) ;
653
655
654
- let tdView ;
655
656
if ( ! record ) {
656
- tdView = < td { ... restProps } > { children } </ td > ;
657
- } else {
658
- let { background } = style ! ;
659
- if ( rowContext . hover ) {
660
- background = 'transparent' ;
661
- }
657
+ return (
658
+ < TableCellContext . Provider value = { { isEditing : editing , setIsEditing : setEditing } } >
659
+ < td ref = { ref } { ... restProps } > { children } </ td >
660
+ </ TableCellContext . Provider >
661
+ ) ;
662
+ }
662
663
663
- tdView = (
664
+ let { background } = style ! ;
665
+ if ( rowContext . hover ) {
666
+ background = 'transparent' ;
667
+ }
668
+
669
+ return (
670
+ < TableCellContext . Provider value = { { isEditing : editing , setIsEditing : setEditing } } >
664
671
< TableTd
672
+ ref = { ref }
665
673
{ ...restProps }
666
674
$background = { background }
667
675
$style = { style ! }
@@ -677,17 +685,11 @@ const TableCellView = React.memo((props: {
677
685
: children
678
686
}
679
687
</ TableTd >
680
- ) ;
681
- }
682
-
683
- return (
684
- < TableCellContext . Provider value = { { isEditing : editing , setIsEditing : setEditing } } >
685
- { tdView }
686
688
</ TableCellContext . Provider >
687
689
) ;
688
690
} ) ;
689
691
690
- const TableRowView = React . memo ( ( props : any ) => {
692
+ const TableRowView = React . forwardRef < HTMLTableRowElement , any > ( ( props , ref ) => {
691
693
const [ hover , setHover ] = useState ( false ) ;
692
694
const [ selected , setSelected ] = useState ( false ) ;
693
695
@@ -700,6 +702,7 @@ const TableRowView = React.memo((props: any) => {
700
702
return (
701
703
< TableRowContext . Provider value = { { hover, selected } } >
702
704
< tr
705
+ ref = { ref }
703
706
{ ...props }
704
707
tabIndex = { - 1 }
705
708
onMouseEnter = { handleMouseEnter }
0 commit comments