diff --git a/projects/js-packages/components/components/icon-tooltip/index.tsx b/projects/js-packages/components/components/icon-tooltip/index.tsx index c64b6e74309dd..c51ec4e125d01 100644 --- a/projects/js-packages/components/components/icon-tooltip/index.tsx +++ b/projects/js-packages/components/components/icon-tooltip/index.tsx @@ -41,9 +41,12 @@ const IconTooltip: React.FC< IconTooltipProps > = ( { wide = false, inline = true, shift = false, + hoverShow = false, } ) => { const POPOVER_HELPER_WIDTH = 124; const [ isVisible, setIsVisible ] = useState( false ); + const [ timeoutId, setTimeoutId ] = useState( null ); + const hideTooltip = useCallback( () => setIsVisible( false ), [ setIsVisible ] ); const toggleTooltip = useCallback( e => { @@ -53,6 +56,26 @@ const IconTooltip: React.FC< IconTooltipProps > = ( { [ isVisible, setIsVisible ] ); + const handleMouseEnter = useCallback( () => { + if ( hoverShow ) { + if ( timeoutId ) { + clearTimeout( timeoutId ); + setTimeoutId( null ); + } + setIsVisible( true ); + } + }, [ hoverShow, timeoutId ] ); + + const handleMouseLeave = useCallback( () => { + if ( hoverShow ) { + const id = setTimeout( () => { + setIsVisible( false ); + setTimeoutId( null ); + }, 100 ); + setTimeoutId( id ); + } + }, [ hoverShow ] ); + const args = { // To be compatible with deprecating prop `position`. position: placementsToPositions( placement ), @@ -79,7 +102,12 @@ const IconTooltip: React.FC< IconTooltipProps > = ( { const isForcedToShow = isAnchorWrapper && forceShow; return ( -
+
{ ! isAnchorWrapper && (