Skip to content

Commit

Permalink
fix: scroll issue on resize
Browse files Browse the repository at this point in the history
  • Loading branch information
johnshift committed Apr 8, 2024
1 parent 72c3907 commit a7c47e7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
20 changes: 19 additions & 1 deletion src/shared/components/page-scroll-syncer.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';

import { useEffect } from 'react';
import { useCallback, useEffect } from 'react';

import { useAtom } from 'jotai';

Expand All @@ -27,5 +27,23 @@ export const PageScrollDisableSyncer = ({ shouldDisable }: Props) => {
}
}, [isDesktop, isDisabled, isMounted, setIsDisabled, shouldDisable]);

// Fix scroll disabled on resize (re-enable scroll on large devices)
const checkOnResize = useCallback(() => {
if (window.innerWidth >= DETAILS_BREAKPOINT && isDisabled) {
setIsDisabled(false);
}
}, [isDisabled, setIsDisabled]);

useEffect(() => {
// Invoke check on init
checkOnResize();

window.addEventListener('resize', checkOnResize);

return () => window.removeEventListener('resize', checkOnResize);
}, [checkOnResize]);

return null;
};

const DETAILS_BREAKPOINT = 1280;
19 changes: 0 additions & 19 deletions src/shared/hooks/use-disable-mobile-page-scroll.ts

This file was deleted.

0 comments on commit a7c47e7

Please sign in to comment.