Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2023-04-03 12:10:44 +02:00
parent d6b73b0380
commit 24e3daa6dc
3 changed files with 7 additions and 4 deletions
+1
View File
@@ -67,6 +67,7 @@
"@testing-library/user-event": "^14.0.0",
"@types/node": "^16.11.26",
"cross-fetch": "^3.1.5",
"history": "^5.0.0",
"msw": "^1.0.0"
},
"files": [
@@ -20,7 +20,7 @@ import {
createVersionedContext,
createVersionedValueMap,
} from '@backstage/version-bridge';
import { useUpdateEffect } from 'react-use';
import useUpdateEffect from 'react-use/lib/useUpdateEffect';
/**
* The state of the search modal, as well as functions for changing the modal's
@@ -136,14 +136,15 @@ export function useSearchModal(initialState = false) {
const parentContextValue = parentContext?.atVersion(1);
const isParentContextPresent = !!parentContextValue?.state;
// Monitor route pathname changes to automatically hide the modal.
const { pathname } = useLocation();
// Monitor route changes to automatically hide the modal.
const location = useLocation();
const locationKey = `${location.pathname}${location.search}${location.hash}`;
useUpdateEffect(() => {
setState(prevState => ({
open: prevState.open,
hidden: true,
}));
}, [pathname]);
}, [locationKey]);
// Inherit from parent context, if set.
return isParentContextPresent