Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear hovered part's name when unhovered #47

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/components/PartsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ interface PartsListProps {
names: string[];
handleItemClick: (partName: string, evt: React.MouseEvent<HTMLImageElement>) => void;
handleItemMouseEnter: (partName: string, evt: React.MouseEvent<HTMLImageElement>) => void;
handleItemMouseLeave: (evt: React.MouseEvent<HTMLImageElement>) => void;
}

const PartsList = (props: PartsListProps) => {
const { handleItemClick, handleItemMouseEnter } = props;
const { handleItemClick, handleItemMouseEnter, handleItemMouseLeave } = props;
const handleImageClick = useCallback((evt: React.MouseEvent<HTMLImageElement>) => {
const partName = evt.currentTarget.dataset.name!;
handleItemClick(partName, evt);
Expand All @@ -22,6 +23,9 @@ const PartsList = (props: PartsListProps) => {
const partName = evt.currentTarget.dataset.name!;
handleItemMouseEnter(partName, evt);
}, [handleItemMouseEnter]);
const handleImageMouseLeave = useCallback((evt: React.MouseEvent<HTMLImageElement>) => {
handleItemMouseLeave(evt);
}, [handleItemMouseLeave]);

return (
<div className="parts-list">
Expand All @@ -34,6 +38,7 @@ const PartsList = (props: PartsListProps) => {
loading="lazy"
onClick={handleImageClick}
onMouseEnter={handleImageMouseEnter}
onMouseLeave={handleImageMouseLeave}
/>
))}
</div>
Expand Down
10 changes: 10 additions & 0 deletions src/components/PartsSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ const PartsSearch = () => {
}, []);
const handleFormSubmit = useCallback((evt: React.FormEvent) => {
evt.preventDefault();
if (hoverNameRef.current) {
hoverNameRef.current.textContent = "\xa0";
}
handleSearch();
}, [handleSearch]);

Expand All @@ -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) {
Expand Down Expand Up @@ -145,6 +154,7 @@ const PartsSearch = () => {
names={searchState.result}
handleItemClick={handleItemClick}
handleItemMouseEnter={handleItemMouseEnter}
handleItemMouseLeave={handleItemMouseLeave}
/>}
</div>
<div className="parts-hover-name" ref={hoverNameRef}>&nbsp;</div>
Expand Down