Changed the way lock body scroll works to not scroll to top when user searches for something

This commit is contained in:
Piotr Janosz
2019-08-05 18:56:46 +02:00
committed by fabioberger
parent 16e55457c8
commit d39e90bfa1

View File

@@ -33,15 +33,14 @@ const Overlay = styled.div<IAutocompleteOverlayProps>`
// This could be extracted to reuse
function useLockBodyScroll(): void {
useLayoutEffect(() => {
// Get original value of body styles
const { maxHeight, overflowY } = window.getComputedStyle(document.body);
const html = document.documentElement;
// Prevent scrolling on mount
document.body.style.overflowY = 'hidden';
document.body.style.maxHeight = '100vh';
html.style.overflowY = 'hidden';
html.style.maxHeight = '100vh';
// Re-enable scrolling when component unmounts
return () => {
document.body.style.overflowY = overflowY;
document.body.style.maxHeight = maxHeight;
html.style.overflowY = 'auto';
html.style.maxHeight = '';
};
}, []); // Empty array ensures effect is only run on mount and unmount
}