Skip to content

Commit

Permalink
♿ (js) Improve auto scroll when no host bubble
Browse files Browse the repository at this point in the history
Closes #522
  • Loading branch information
baptisteArno committed May 26, 2023
1 parent 68f0202 commit 0ca48e4
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/embeds/js/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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}
Expand Down
2 changes: 2 additions & 0 deletions packages/embeds/js/src/components/InputChatBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/embeds/react/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 0ca48e4

Please sign in to comment.