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}
|
||||
/>
|
||||
</AutocompleteWrapper>
|
||||
{currentRefinement && <AutocompleteOverlay onClick={onSuggestionsClearRequested} />}
|
||||
{currentRefinement && (
|
||||
<AutocompleteOverlay onClick={onSuggestionsClearRequested} shouldLockScroll={!isHome} />
|
||||
)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -3,10 +3,13 @@ import styled from 'styled-components';
|
||||
|
||||
interface IAutocompleteOverlayProps {
|
||||
onClick: () => void;
|
||||
shouldLockScroll?: boolean;
|
||||
}
|
||||
|
||||
export const AutocompleteOverlay: React.FC<IAutocompleteOverlayProps> = ({ onClick }) => {
|
||||
// useLockBodyScroll();
|
||||
export const AutocompleteOverlay: React.FC<IAutocompleteOverlayProps> = ({ onClick, shouldLockScroll }) => {
|
||||
if (shouldLockScroll) {
|
||||
useLockBodyScroll();
|
||||
}
|
||||
|
||||
return <Overlay onClick={onClick} />;
|
||||
};
|
||||
@@ -28,7 +31,7 @@ const Overlay = styled.div<IAutocompleteOverlayProps>`
|
||||
`;
|
||||
|
||||
// This could be extracted to reuse
|
||||
function useLockBodyScroll() {
|
||||
function useLockBodyScroll(): void {
|
||||
useLayoutEffect(() => {
|
||||
// Get original value of body styles
|
||||
const { maxHeight, overflowY } = window.getComputedStyle(document.body);
|
||||
|
||||
Reference in New Issue
Block a user