2
0

(js) Improve auto scroll when no host bubble

Closes #522
This commit is contained in:
Baptiste Arnaud
2023-05-26 18:31:13 +02:00
parent 68f0202601
commit 0ca48e4c08
4 changed files with 9 additions and 3 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@typebot.io/js",
"version": "0.0.58",
"version": "0.0.59",
"description": "Javascript library to display typebots on your website",
"type": "module",
"main": "dist/index.js",

View File

@ -21,13 +21,16 @@ type Props = Pick<ChatReply, 'messages' | 'input'> & {
}
export const ChatChunk = (props: Props) => {
let inputRef: HTMLDivElement | undefined
const [displayedMessageIndex, setDisplayedMessageIndex] = createSignal(0)
onMount(() => {
if (props.messages.length === 0) {
props.onAllBubblesDisplayed()
}
props.onScrollToBottom()
props.onScrollToBottom(
inputRef?.offsetTop ? inputRef?.offsetTop - 50 : undefined
)
})
const displayNextMessage = async (bubbleOffsetTop?: number) => {
@ -84,6 +87,7 @@ export const ChatChunk = (props: Props) => {
</Show>
{props.input && displayedMessageIndex() === props.messages.length && (
<InputChatBlock
ref={inputRef}
block={props.input}
inputIndex={props.inputIndex}
onSubmit={props.onSubmit}

View File

@ -35,6 +35,7 @@ import { SinglePictureChoice } from '@/features/blocks/inputs/pictureChoice/Sing
import { MultiplePictureChoice } from '@/features/blocks/inputs/pictureChoice/MultiplePictureChoice'
type Props = {
ref: HTMLDivElement | undefined
block: NonNullable<ChatReply['input']>
hasHostAvatar: boolean
guestAvatar?: Theme['chat']['guestAvatar']
@ -72,6 +73,7 @@ export const InputChatBlock = (props: Props) => {
<div
class="flex justify-end animate-fade-in gap-2"
data-blockid={props.block.id}
ref={props.ref}
>
{props.hasHostAvatar && (
<div

View File

@ -1,6 +1,6 @@
{
"name": "@typebot.io/react",
"version": "0.0.58",
"version": "0.0.59",
"description": "React library to display typebots on your website",
"main": "dist/index.js",
"types": "dist/index.d.ts",