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