Skip to content

Commit 4850692

Browse files
author
Matteo Merola
committed
fixed #14 automatic scroll to bottom
@senky I added another config prop `alwaysScrollToBottom` when set to true it alwasy scrolls to bottom, when set to false (or unset) it scrolls to bottom only when reading the last sent/received message.
1 parent 6add5f1 commit 4850692

File tree

6 files changed

+25
-5
lines changed

6 files changed

+25
-5
lines changed

demo/src/App.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
:showEmoji="true"
1313
:showFile="true"
1414
:showTypingIndicator="showTypingIndicator"
15-
:colors="colors" />
15+
:colors="colors"
16+
:alwaysScrollToBottom="alwaysScrollToBottom" />
1617
<p class="text-center toggle">
1718
<a v-if="!isChatOpen" :style="{color: linkColor}" href="#" @click.prevent="openChat()">Open the chat window</a>
1819
<a v-else :style="{color: linkColor}" href="#" @click.prevent="closeChat()">Close the chat window</a>
@@ -52,7 +53,8 @@ export default {
5253
showTypingIndicator: false,
5354
colors: null,
5455
availableColors,
55-
chosenColor: null
56+
chosenColor: null,
57+
alwaysScrollToBottom: false
5658
}
5759
},
5860
created() {

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/ssr.index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ChatWindow.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
:chatImageUrl="agentProfile.imageUrl"
1313
:showTypingIndicator="showTypingIndicator"
1414
:colors="colors"
15+
:alwaysScrollToBottom="alwaysScrollToBottom"
1516
/>
1617
<UserInput
1718
:showEmoji="showEmoji"
@@ -73,6 +74,10 @@ export default {
7374
colors: {
7475
type: Object,
7576
required: true
77+
},
78+
alwaysScrollToBottom: {
79+
type: Boolean,
80+
required: true
7681
}
7782
},
7883
data() {

src/Launcher.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
:placeholder="placeholder"
1919
:showTypingIndicator="showTypingIndicator"
2020
:colors="colors"
21+
:alwaysScrollToBottom="alwaysScrollToBottom"
2122
/>
2223
</div>
2324
</template>
@@ -112,6 +113,10 @@ export default {
112113
}
113114
}
114115
}
116+
},
117+
alwaysScrollToBottom: {
118+
type: Boolean,
119+
default: () => false
115120
}
116121
},
117122
data () {

src/MessageList.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,26 @@ export default {
2828
colors: {
2929
type: Object,
3030
required: true
31+
},
32+
alwaysScrollToBottom: {
33+
type: Boolean,
34+
required: true
3135
}
3236
},
3337
methods: {
3438
_scrollDown () {
3539
this.$refs.scrollList.scrollTop = this.$refs.scrollList.scrollHeight
40+
},
41+
shouldScrollToBottom() {
42+
return this.alwaysScrollToBottom || (this.$refs.scrollList.scrollTop > this.$refs.scrollList.scrollHeight - 300)
3643
}
3744
},
3845
mounted () {
3946
this._scrollDown()
4047
},
4148
updated () {
42-
this.$nextTick(this._scrollDown())
49+
if (this.shouldScrollToBottom())
50+
this.$nextTick(this._scrollDown())
4351
}
4452
}
4553
</script>

0 commit comments

Comments
 (0)