chore: update log viewer to trigger scrolled-to-top event when scroll top is close enough
@@ -80,6 +80,9 @@ const DATETIME_FORMAT = `[${DATETIME_PREFIX}]YYYY-MM-DD, HH:mm:ss${DATETIME_SUFF
// Max datetime size: DATETIME_FORMAT (plus 1 for a space suffix)
const MAX_DATETIME_LENGTH = 23;
+// Number of pixels from the top of the scroll to trigger the `onScrollToTop` callback.
+const SCROLL_TOP_THRESHOLD = 50;
+
const ICON_WIDTH = 26;
const defaultLogConfig = {
@@ -259,10 +262,10 @@ const LogViewer: React.FC<Props> = forwardRef((
if (logs.length === 0) return;
// Check to make sure the scroll position is at the top.
- if (scroll.scrollTop > 0) return;
+ if (scroll.scrollTop > SCROLL_TOP_THRESHOLD) return;
// Skip if the previous state was already at the top.
- if (previousScroll.scrollTop === 0) return;
+ if (previousScroll.scrollTop <= SCROLL_TOP_THRESHOLD) return;
// Skip if there isn't a callback.
if (!onScrollToTop) return;
