🚸 Improve auto scroll behavior
Now only based on bottom of last element if it is in view
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@typebot.io/js",
|
||||
"version": "0.2.79",
|
||||
"version": "0.2.80",
|
||||
"description": "Javascript library to display typebots on your website",
|
||||
"type": "module",
|
||||
"main": "dist/index.js",
|
||||
|
@ -234,17 +234,15 @@ export const ConversationContainer = (props: Props) => {
|
||||
}
|
||||
const lastElementRect = lastElement.getBoundingClientRect()
|
||||
const containerRect = chatContainer.getBoundingClientRect()
|
||||
const lastElementTopRelative =
|
||||
lastElementRect.top - containerRect.top + chatContainer.scrollTop
|
||||
|
||||
const isLastElementInVisibleArea =
|
||||
lastElementTopRelative < chatContainer.scrollTop + containerRect.height &&
|
||||
lastElementTopRelative + lastElementRect.height > chatContainer.scrollTop
|
||||
const isBottomOfLastElementInView =
|
||||
lastElementRect.top + lastElementRect.height < containerRect.height
|
||||
|
||||
if (isLastElementInVisibleArea)
|
||||
if (isBottomOfLastElementInView) {
|
||||
setTimeout(() => {
|
||||
chatContainer?.scrollTo(0, lastElement.offsetTop - offset)
|
||||
}, 50)
|
||||
}
|
||||
}
|
||||
|
||||
const handleAllBubblesDisplayed = async () => {
|
||||
|
@ -18,7 +18,7 @@ export const Buttons = (props: Props) => {
|
||||
const [filteredItems, setFilteredItems] = createSignal(props.defaultItems)
|
||||
|
||||
onMount(() => {
|
||||
if (!isMobile() && inputRef) inputRef.focus()
|
||||
if (!isMobile() && inputRef) inputRef.focus({ preventScroll: true })
|
||||
})
|
||||
|
||||
const handleClick = (itemIndex: number) =>
|
||||
|
@ -19,7 +19,7 @@ export const MultipleChoicesForm = (props: Props) => {
|
||||
const [selectedItemIds, setSelectedItemIds] = createSignal<string[]>([])
|
||||
|
||||
onMount(() => {
|
||||
if (!isMobile() && inputRef) inputRef.focus()
|
||||
if (!isMobile() && inputRef) inputRef.focus({ preventScroll: true })
|
||||
})
|
||||
|
||||
const handleClick = (itemId: string) => {
|
||||
|
@ -33,7 +33,7 @@ export const EmailInput = (props: Props) => {
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
if (!isMobile() && inputRef) inputRef.focus()
|
||||
if (!isMobile() && inputRef) inputRef.focus({ preventScroll: true })
|
||||
window.addEventListener('message', processIncomingEvent)
|
||||
})
|
||||
|
||||
|
@ -36,7 +36,7 @@ export const NumberInput = (props: NumberInputProps) => {
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
if (!isMobile() && inputRef) inputRef.focus()
|
||||
if (!isMobile() && inputRef) inputRef.focus({ preventScroll: true })
|
||||
window.addEventListener('message', processIncomingEvent)
|
||||
})
|
||||
|
||||
|
@ -90,7 +90,7 @@ export const PhoneInput = (props: PhoneInputProps) => {
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
if (!isMobile() && inputRef) inputRef.focus()
|
||||
if (!isMobile() && inputRef) inputRef.focus({ preventScroll: true })
|
||||
window.addEventListener('message', processIncomingEvent)
|
||||
})
|
||||
|
||||
|
@ -22,7 +22,7 @@ export const MultiplePictureChoice = (props: Props) => {
|
||||
const [totalLoadedImages, setTotalLoadedImages] = createSignal(0)
|
||||
|
||||
onMount(() => {
|
||||
if (!isMobile() && inputRef) inputRef.focus()
|
||||
if (!isMobile() && inputRef) inputRef.focus({ preventScroll: true })
|
||||
})
|
||||
|
||||
const handleClick = (itemId: string) => {
|
||||
|
@ -18,7 +18,7 @@ export const SinglePictureChoice = (props: Props) => {
|
||||
const [totalLoadedImages, setTotalLoadedImages] = createSignal(0)
|
||||
|
||||
onMount(() => {
|
||||
if (!isMobile() && inputRef) inputRef.focus()
|
||||
if (!isMobile() && inputRef) inputRef.focus({ preventScroll: true })
|
||||
})
|
||||
|
||||
const handleClick = (itemIndex: number) => {
|
||||
|
@ -40,7 +40,10 @@ export const TextInput = (props: Props) => {
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
if (!isMobile() && inputRef) inputRef.focus()
|
||||
if (!isMobile() && inputRef)
|
||||
inputRef.focus({
|
||||
preventScroll: true,
|
||||
})
|
||||
window.addEventListener('message', processIncomingEvent)
|
||||
})
|
||||
|
||||
|
@ -39,7 +39,10 @@ export const UrlInput = (props: Props) => {
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
if (!isMobile() && inputRef) inputRef.focus()
|
||||
if (!isMobile() && inputRef)
|
||||
inputRef.focus({
|
||||
preventScroll: true,
|
||||
})
|
||||
window.addEventListener('message', processIncomingEvent)
|
||||
})
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@typebot.io/nextjs",
|
||||
"version": "0.2.79",
|
||||
"version": "0.2.80",
|
||||
"description": "Convenient library to display typebots on your Next.js website",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@typebot.io/react",
|
||||
"version": "0.2.79",
|
||||
"version": "0.2.80",
|
||||
"description": "Convenient library to display typebots on your React app",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
|
Reference in New Issue
Block a user