Added lock body scroll for search in header
This commit is contained in:
committed by
fabioberger
parent
42e0d608c8
commit
1ba54af4e2
@@ -125,7 +125,9 @@ const CustomAutoComplete: React.FC<IAutoCompleteProps> = ({ isHome = false, hits
|
|||||||
getSectionSuggestions={getSectionSuggestions}
|
getSectionSuggestions={getSectionSuggestions}
|
||||||
/>
|
/>
|
||||||
</AutocompleteWrapper>
|
</AutocompleteWrapper>
|
||||||
{currentRefinement && <AutocompleteOverlay onClick={onSuggestionsClearRequested} />}
|
{currentRefinement && (
|
||||||
|
<AutocompleteOverlay onClick={onSuggestionsClearRequested} shouldLockScroll={!isHome} />
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,10 +3,13 @@ import styled from 'styled-components';
|
|||||||
|
|
||||||
interface IAutocompleteOverlayProps {
|
interface IAutocompleteOverlayProps {
|
||||||
onClick: () => void;
|
onClick: () => void;
|
||||||
|
shouldLockScroll?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const AutocompleteOverlay: React.FC<IAutocompleteOverlayProps> = ({ onClick }) => {
|
export const AutocompleteOverlay: React.FC<IAutocompleteOverlayProps> = ({ onClick, shouldLockScroll }) => {
|
||||||
// useLockBodyScroll();
|
if (shouldLockScroll) {
|
||||||
|
useLockBodyScroll();
|
||||||
|
}
|
||||||
|
|
||||||
return <Overlay onClick={onClick} />;
|
return <Overlay onClick={onClick} />;
|
||||||
};
|
};
|
||||||
@@ -28,7 +31,7 @@ const Overlay = styled.div<IAutocompleteOverlayProps>`
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
// This could be extracted to reuse
|
// This could be extracted to reuse
|
||||||
function useLockBodyScroll() {
|
function useLockBodyScroll(): void {
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
// Get original value of body styles
|
// Get original value of body styles
|
||||||
const { maxHeight, overflowY } = window.getComputedStyle(document.body);
|
const { maxHeight, overflowY } = window.getComputedStyle(document.body);
|
||||||
|
|||||||
Reference in New Issue
Block a user