Skip to content

Commit

Permalink
fixed #14 automatic scroll to bottom
Browse files Browse the repository at this point in the history
@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.
  • Loading branch information
Matteo Merola committed Aug 4, 2018
1 parent 6add5f1 commit 4850692
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 5 deletions.
6 changes: 4 additions & 2 deletions demo/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
:showEmoji="true"
:showFile="true"
:showTypingIndicator="showTypingIndicator"
:colors="colors" />
:colors="colors"
:alwaysScrollToBottom="alwaysScrollToBottom" />
<p class="text-center toggle">
<a v-if="!isChatOpen" :style="{color: linkColor}" href="#" @click.prevent="openChat()">Open the chat window</a>
<a v-else :style="{color: linkColor}" href="#" @click.prevent="closeChat()">Close the chat window</a>
Expand Down Expand Up @@ -52,7 +53,8 @@ export default {
showTypingIndicator: false,
colors: null,
availableColors,
chosenColor: null
chosenColor: null,
alwaysScrollToBottom: false
}
},
created() {
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ssr.index.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions src/ChatWindow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
:chatImageUrl="agentProfile.imageUrl"
:showTypingIndicator="showTypingIndicator"
:colors="colors"
:alwaysScrollToBottom="alwaysScrollToBottom"
/>
<UserInput
:showEmoji="showEmoji"
Expand Down Expand Up @@ -73,6 +74,10 @@ export default {
colors: {
type: Object,
required: true
},
alwaysScrollToBottom: {
type: Boolean,
required: true
}
},
data() {
Expand Down
5 changes: 5 additions & 0 deletions src/Launcher.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
:placeholder="placeholder"
:showTypingIndicator="showTypingIndicator"
:colors="colors"
:alwaysScrollToBottom="alwaysScrollToBottom"
/>
</div>
</template>
Expand Down Expand Up @@ -112,6 +113,10 @@ export default {
}
}
}
},
alwaysScrollToBottom: {
type: Boolean,
default: () => false
}
},
data () {
Expand Down
10 changes: 9 additions & 1 deletion src/MessageList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,26 @@ export default {
colors: {
type: Object,
required: true
},
alwaysScrollToBottom: {
type: Boolean,
required: true
}
},
methods: {
_scrollDown () {
this.$refs.scrollList.scrollTop = this.$refs.scrollList.scrollHeight
},
shouldScrollToBottom() {
return this.alwaysScrollToBottom || (this.$refs.scrollList.scrollTop > this.$refs.scrollList.scrollHeight - 300)
}
},
mounted () {
this._scrollDown()
},
updated () {
this.$nextTick(this._scrollDown())
if (this.shouldScrollToBottom())
this.$nextTick(this._scrollDown())
}
}
</script>
Expand Down

0 comments on commit 4850692

Please sign in to comment.