From c9b9684d53b09efafdadc6154130c40e3d719e47 Mon Sep 17 00:00:00 2001 From: Ruben Thoms Date: Mon, 11 Sep 2023 15:42:48 +0200 Subject: [PATCH] Removed unnecessary deps and added scroll capturing to bounding rect --- frontend/src/lib/components/Dropdown/dropdown.tsx | 9 +-------- frontend/src/lib/hooks/useElementBoundingRect.ts | 2 ++ 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/frontend/src/lib/components/Dropdown/dropdown.tsx b/frontend/src/lib/components/Dropdown/dropdown.tsx index 6cdb4dfe1..870f38617 100644 --- a/frontend/src/lib/components/Dropdown/dropdown.tsx +++ b/frontend/src/lib/components/Dropdown/dropdown.tsx @@ -166,14 +166,7 @@ export const Dropdown = withDefaults()(defaultProps, (props) => { setOptionIndexWithFocusToCurrentSelection(); } } - }, [ - inputBoundingRect, - dropdownVisible, - filteredOptions, - selection, - setOptionIndexWithFocusToCurrentSelection, - setStartIndex, - ]); + }, [inputBoundingRect, dropdownVisible, filteredOptions, selection]); const handleOptionClick = React.useCallback( (value: string) => { diff --git a/frontend/src/lib/hooks/useElementBoundingRect.ts b/frontend/src/lib/hooks/useElementBoundingRect.ts index fa3604654..916e13b60 100644 --- a/frontend/src/lib/hooks/useElementBoundingRect.ts +++ b/frontend/src/lib/hooks/useElementBoundingRect.ts @@ -13,6 +13,7 @@ export function useElementBoundingRect(ref: React.RefObject): DOMRe const resizeObserver = new ResizeObserver(handleResize); window.addEventListener("resize", handleResize); + window.addEventListener("scroll", handleResize, true); if (ref.current) { handleResize(); @@ -22,6 +23,7 @@ export function useElementBoundingRect(ref: React.RefObject): DOMRe return () => { resizeObserver.disconnect(); window.removeEventListener("resize", handleResize); + window.removeEventListener("scroll", handleResize, true); }; }, [ref]);