diff --git a/src/components/PartsList.tsx b/src/components/PartsList.tsx index 6168ec6..a214ca5 100644 --- a/src/components/PartsList.tsx +++ b/src/components/PartsList.tsx @@ -10,10 +10,11 @@ interface PartsListProps { names: string[]; handleItemClick: (partName: string, evt: React.MouseEvent) => void; handleItemMouseEnter: (partName: string, evt: React.MouseEvent) => void; + handleItemMouseLeave: (evt: React.MouseEvent) => void; } const PartsList = (props: PartsListProps) => { - const { handleItemClick, handleItemMouseEnter } = props; + const { handleItemClick, handleItemMouseEnter, handleItemMouseLeave } = props; const handleImageClick = useCallback((evt: React.MouseEvent) => { const partName = evt.currentTarget.dataset.name!; handleItemClick(partName, evt); @@ -22,6 +23,9 @@ const PartsList = (props: PartsListProps) => { const partName = evt.currentTarget.dataset.name!; handleItemMouseEnter(partName, evt); }, [handleItemMouseEnter]); + const handleImageMouseLeave = useCallback((evt: React.MouseEvent) => { + handleItemMouseLeave(evt); + }, [handleItemMouseLeave]); return (
@@ -34,6 +38,7 @@ const PartsList = (props: PartsListProps) => { loading="lazy" onClick={handleImageClick} onMouseEnter={handleImageMouseEnter} + onMouseLeave={handleImageMouseLeave} /> ))}
diff --git a/src/components/PartsSearch.tsx b/src/components/PartsSearch.tsx index 08c456e..5ba4bd0 100644 --- a/src/components/PartsSearch.tsx +++ b/src/components/PartsSearch.tsx @@ -95,6 +95,9 @@ const PartsSearch = () => { }, []); const handleFormSubmit = useCallback((evt: React.FormEvent) => { evt.preventDefault(); + if (hoverNameRef.current) { + hoverNameRef.current.textContent = "\xa0"; + } handleSearch(); }, [handleSearch]); @@ -105,6 +108,12 @@ const PartsSearch = () => { } hoverNameRef.current.textContent = partName; }, []); + const handleItemMouseLeave = useCallback(() => { + if (!hoverNameRef.current) { + return; + } + hoverNameRef.current.textContent = "\xa0"; + }, []); const dispatch = useDispatch(); const handleItemClick = useCallback((partName: string, evt: React.MouseEvent) => { if (evt.shiftKey) { @@ -145,6 +154,7 @@ const PartsSearch = () => { names={searchState.result} handleItemClick={handleItemClick} handleItemMouseEnter={handleItemMouseEnter} + handleItemMouseLeave={handleItemMouseLeave} />}