4
4
ForwardedRef ,
5
5
forwardRef ,
6
6
ReactNode ,
7
+ useCallback ,
8
+ useEffect ,
7
9
useMemo ,
8
10
useState ,
9
11
} from 'react' ;
@@ -497,7 +499,7 @@ const ItemBase = <T extends HTMLElement = HTMLDivElement>(
497
499
const mergedLabelRef = useCombinedRefs ( ( labelProps as any ) ?. ref ) ;
498
500
const [ isLabelOverflowed , setIsLabelOverflowed ] = useState ( false ) ;
499
501
500
- const checkLabelOverflow = ( ) => {
502
+ const checkLabelOverflow = useCallback ( ( ) => {
501
503
const label = mergedLabelRef . current ;
502
504
if ( ! label ) {
503
505
setIsLabelOverflowed ( false ) ;
@@ -507,28 +509,25 @@ const ItemBase = <T extends HTMLElement = HTMLDivElement>(
507
509
const hasOverflow = label . scrollWidth > label . clientWidth ;
508
510
509
511
setIsLabelOverflowed ( hasOverflow ) ;
510
- } ;
512
+ } , [ mergedLabelRef ] ) ;
511
513
512
- useLayoutEffect ( ( ) => {
514
+ useEffect ( ( ) => {
513
515
if ( isAutoTooltipEnabled ) {
514
516
checkLabelOverflow ( ) ;
515
517
}
516
- } , [ children , isAutoTooltipEnabled ] ) ;
518
+ } , [ children , isAutoTooltipEnabled , checkLabelOverflow ] ) ;
517
519
518
- useLayoutEffect ( ( ) => {
520
+ useEffect ( ( ) => {
519
521
if ( ! isAutoTooltipEnabled ) return ;
520
522
521
523
const label = mergedLabelRef . current ;
522
524
if ( ! label ) return ;
523
525
524
- // Initial check
525
- checkLabelOverflow ( ) ;
526
+ const resizeObserver = new ResizeObserver ( checkLabelOverflow ) ;
527
+ resizeObserver . observe ( label ) ;
526
528
527
- // const resizeObserver = new ResizeObserver(checkLabelOverflow);
528
- // resizeObserver.observe(label);
529
-
530
- // return () => resizeObserver.disconnect();
531
- } , [ mergedLabelRef . current , isAutoTooltipEnabled ] ) ;
529
+ return ( ) => resizeObserver . disconnect ( ) ;
530
+ } , [ isAutoTooltipEnabled , checkLabelOverflow , children , mergedLabelRef ] ) ;
532
531
533
532
const finalLabelProps = useMemo ( ( ) => {
534
533
return {
0 commit comments