Skip to content

Commit

Permalink
fix: smooth scroll to index with windowScroll
Browse files Browse the repository at this point in the history
Fixes #709
Fixes #687 (most likely)
  • Loading branch information
petyosi committed Jul 11, 2022
1 parent ffceed4 commit cea8d6a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/hooks/useScrollTop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ export default function useScrollTop(
const handler = useCallback(
(ev: Event) => {
const el = ev.target as HTMLElement
const scrollTop =
(el as any) === window || (el as any) === document ? window.pageYOffset || document.documentElement.scrollTop : el.scrollTop
const scrollHeight = (el as any) === window ? document.documentElement.scrollHeight : el.scrollHeight
const viewportHeight = (el as any) === window ? window.innerHeight : el.offsetHeight
const windowScroll = (el as any) === window || (el as any) === document
const scrollTop = windowScroll ? window.pageYOffset || document.documentElement.scrollTop : el.scrollTop
const scrollHeight = windowScroll ? document.documentElement.scrollHeight : el.scrollHeight
const viewportHeight = windowScroll ? window.innerHeight : el.offsetHeight

const call = () => {
scrollContainerStateCallback({
Expand All @@ -43,7 +43,7 @@ export default function useScrollTop(
shouldFlushSync.current = false

if (scrollTopTarget.current !== null) {
if (scrollTop === scrollTopTarget.current || scrollTop <= 0 || scrollTop === el.scrollHeight - correctItemSize(el, 'height')) {
if (scrollTop === scrollTopTarget.current || scrollTop <= 0 || scrollTop === scrollHeight - viewportHeight) {
scrollTopTarget.current = null
smoothScrollTargetReached(true)
if (timeoutRef.current) {
Expand Down

0 comments on commit cea8d6a

Please sign in to comment.