Skip to content

Commit 2fc1198

Browse files
committed
fix: make scroll to bottom buttom ignore spacer and appear when we are scrolled above spacer
1 parent 1e7a852 commit 2fc1198

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

custom/CustomAutoScrollContainer.vue

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,16 @@ onUnmounted(() => {
8989
observer?.disconnect()
9090
})
9191
92-
function isNearBottom(): boolean {
92+
function isNearBottom(customThreshold?: number): boolean {
9393
const container = containerRef.value?.scrollEl
9494
if (!container) return true
9595
9696
const { scrollTop, scrollHeight, clientHeight } = container
9797
scrollParams.value.scrollTop = scrollTop
9898
scrollParams.value.scrollHeight = scrollHeight
9999
scrollParams.value.clientHeight = clientHeight
100-
return scrollHeight - scrollTop - clientHeight <= props.threshold
100+
const threshold = customThreshold ?? props.threshold
101+
return scrollHeight - scrollTop - clientHeight <= threshold
101102
}
102103
103104
function scrollToBottom(force = false): void {
@@ -119,7 +120,7 @@ function hasScrollbar(): boolean {
119120
}
120121
121122
122-
function handleScroll(detectScrollDown = true): void {
123+
function handleScroll(detectScrollDown = true, customThreshold?: number): void {
123124
const container = containerRef.value.scrollEl
124125
if (!container) return
125126
@@ -130,7 +131,7 @@ function handleScroll(detectScrollDown = true): void {
130131
lastScrollHeight = scrollHeight
131132
return
132133
}
133-
if (isNearBottom()) {
134+
if (isNearBottom(customThreshold)) {
134135
isUserScrolledUp.value = false
135136
} else {
136137
const isScrollingUp = scrollTop < lastScrollTop

custom/conversation_area/ConversationArea.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
:enabled="!showScrollToBottomButton"
1515
class="relative h-full flex flex-col overflow-y-auto translate-x-[-50%] left-1/2"
1616
ref="scrollContainer"
17-
:threshold="10"
17+
:threshold="THRESHOLD_TO_SHOW_BUTTON"
1818
behavior="smooth"
1919
:wrapperStyle = "{
2020
height: '100%',
@@ -111,6 +111,7 @@ const showBottomSpacer = ref(false);
111111
const spacerHeight = ref(0);
112112
const MASK_HEIGHT = 20;
113113
const EMPTY_MESSAGE_HEIGHT = 18;
114+
const THRESHOLD_TO_SHOW_BUTTON = 10;
114115
let messageResizeObserver: ResizeObserver | null = null;
115116
let observedLastUserMessageElement: HTMLElement | null = null;
116117
let observedLastAgentMessageElement: HTMLElement | null = null;
@@ -275,7 +276,7 @@ async function handleSendMessage() {
275276
276277
function recalculateScroll() {
277278
if (scrollContainer.value) {
278-
scrollContainer.value.handleScroll(false);
279+
scrollContainer.value.handleScroll(false,spacerHeight.value + THRESHOLD_TO_SHOW_BUTTON);
279280
const isScrolledUp = scrollContainer.value.isUserScrolledUp();
280281
showScrollToBottomButton.value = !!isScrolledUp;
281282
}

0 commit comments

Comments
 (0)