diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2022-11-29 10:16:00 +0100 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2022-11-29 10:16:00 +0100 |
| commit | cea9f011e3cf32eeae83e91befde8263976904a5 (patch) | |
| tree | 73dc6dcd1d4561e6227456064bc985d1dc2075cc /gui/src | |
| parent | dcd158ed864389b8905715321bfb2d41dc319fad (diff) | |
| download | mullvadvpn-cea9f011e3cf32eeae83e91befde8263976904a5.tar.xz mullvadvpn-cea9f011e3cf32eeae83e91befde8263976904a5.zip | |
Move scrollIntoView to ScrollPositionContext
Diffstat (limited to 'gui/src')
| -rw-r--r-- | gui/src/renderer/components/select-location/RelayListContext.tsx | 4 | ||||
| -rw-r--r-- | gui/src/renderer/components/select-location/ScrollPositionContext.tsx | 6 |
2 files changed, 8 insertions, 2 deletions
diff --git a/gui/src/renderer/components/select-location/RelayListContext.tsx b/gui/src/renderer/components/select-location/RelayListContext.tsx index b37cced8b5..0c99125605 100644 --- a/gui/src/renderer/components/select-location/RelayListContext.tsx +++ b/gui/src/renderer/components/select-location/RelayListContext.tsx @@ -179,7 +179,7 @@ function useRelayList( // Return all RelayLocations that should be expanded function useExpandedLocations(filteredLocations: Array<IRelayLocationRedux>) { const { locationType, searchTerm } = useSelectLocationContext(); - const { spacePreAllocationViewRef, scrollViewRef } = useScrollPositionContext(); + const { spacePreAllocationViewRef, scrollIntoView } = useScrollPositionContext(); const relaySettings = useNormalRelaySettings(); const bridgeSettings = useNormalBridgeSettings(); @@ -217,7 +217,7 @@ function useExpandedLocations(filteredLocations: Array<IRelayLocationRedux>) { if (invokedByUser) { locationRect.height += expandedContentHeight; spacePreAllocationViewRef.current?.allocate(expandedContentHeight); - scrollViewRef.current?.scrollIntoView(locationRect); + scrollIntoView(locationRect); } }, [], diff --git a/gui/src/renderer/components/select-location/ScrollPositionContext.tsx b/gui/src/renderer/components/select-location/ScrollPositionContext.tsx index cdb7aba044..b020e76227 100644 --- a/gui/src/renderer/components/select-location/ScrollPositionContext.tsx +++ b/gui/src/renderer/components/select-location/ScrollPositionContext.tsx @@ -17,6 +17,7 @@ interface ScrollPositionContext { spacePreAllocationViewRef: React.RefObject<SpacePreAllocationView>; saveScrollPosition: () => void; resetScrollPositions: () => void; + scrollIntoView: (rect: DOMRect) => void; } type ScrollPosition = [number, number]; @@ -58,6 +59,10 @@ export function ScrollPositionContextProvider(props: ScrollPositionContextProps) } }, [locationType]); + const scrollIntoView = useCallback((rect: DOMRect) => { + scrollViewRef.current?.scrollIntoView(rect); + }, []); + const value = useMemo( () => ({ scrollPositions, @@ -66,6 +71,7 @@ export function ScrollPositionContextProvider(props: ScrollPositionContextProps) spacePreAllocationViewRef, saveScrollPosition, resetScrollPositions, + scrollIntoView, }), [saveScrollPosition, resetScrollPositions], ); |
