Skip to content

Commit

Permalink
Merge pull request #280 from samarpita-bhaumik/taxonomy1
Browse files Browse the repository at this point in the history
Update PathService.tsx
  • Loading branch information
nerdalert authored Oct 20, 2024
2 parents 6172719 + 50593b2 commit 82a4580
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/components/PathService/PathService.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const PathService: React.FC<PathServiceProps> = ({ reset, rootPath, path, handle
const [items, setItems] = useState<string[]>([]);
const [showDropdown, setShowDropdown] = useState<boolean>(false);
const inputRef = useRef<HTMLInputElement>(null);
const componentRef = useRef<HTMLDivElement>(null); // Add a ref to the entire component
const [validPath, setValidPath] = React.useState<ValidatedOptions>();

const validatePath = () => {
Expand All @@ -30,7 +31,6 @@ const PathService: React.FC<PathServiceProps> = ({ reset, rootPath, path, handle
return;
}
setValidPath(ValidatedOptions.error);
return;
};

const fetchData = async (subpath: string) => {
Expand Down Expand Up @@ -93,6 +93,20 @@ const PathService: React.FC<PathServiceProps> = ({ reset, rootPath, path, handle
validatePath();
}, [inputValue]);

useEffect(() => {
//Dropdown menu closed when field is clicked away from
const handleClickOutside = (event: MouseEvent) => {
if (componentRef.current && !componentRef.current.contains(event.target as Node)) {
setShowDropdown(false);
}
};

document.addEventListener('mousedown', handleClickOutside);
return () => {
document.removeEventListener('mousedown', handleClickOutside);
};
}, []);

const handleChange = (value: string) => {
setInputValue(value);
};
Expand Down Expand Up @@ -135,7 +149,7 @@ const PathService: React.FC<PathServiceProps> = ({ reset, rootPath, path, handle
};

return (
<div>
<div ref={componentRef}>
<SearchInput
ref={inputRef}
placeholder="Type to find taxonomy path"
Expand Down

0 comments on commit 82a4580

Please sign in to comment.