Coder Social home page Coder Social logo

theomessin / vue-chat-scroll Goto Github PK

View Code? Open in Web Editor NEW
571.0 7.0 76.0 484 KB

🖱️ Vue directive to keep things scrolled to the bottom.

Home Page: https://jsfiddle.net/theomessin/n7542hk1/

License: MIT License

JavaScript 100.00%
javascript vuejs vuejs2 scrolling chat

vue-chat-scroll's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

vue-chat-scroll's Issues

Prevent scroll down when user has scrolled up

Hello,

I'm using this in a chat app to scroll to the bottom of a div when a new message is received. The problem is if the user has scrolled up within the div (to view older messages), then when they receive a new message it automatically scrolls to the bottom, which is annoying. Could an option be added for it to only scroll down, if the user hasn't scrolled up?

Thanks!

Write some tests

Currently this library is untested. Would like to at least test the directive code (with all configuration cases). Ideally, we'd test the module bundling (s well (we used to have loads of issues with that once upon a time). Testing importing using a <script> tag would also be nice. Would also like to use GitHub Actions to run tests automagically.

How to debug if it is loaded?

Describe the bug
I'm pretty new to vue, sorry.

I've included this in my package.json then in my main.js after importing vue:
import VueChatScroll from "vue-chat-scroll";
Vue.use(VueChatScroll);

In my component I use <ul v-chat-scroll class="mt2">

When I load the page and my ul has enough messages to require scrolling, no scroll happens.

Any tips how to see if it was loaded properly? The only thing I could think of is using v-chat-scroll="true" in the html instead and making sure that property wasn't set in the result (it wasn't). I have the vue chrome devtools addon and poked around some but couldn't see anything.

There's no console logs or errors.

Also - I either Vue.use(VueChatScroll) OR include the script in my index.html, right? I tried including the script as well and nothing still happened. There's no vue js script linked in there though. I used the CDN script since I couldn't figure out how to get /dist/vue-chat-scroll.js to work properly via the "npm serve" server (it would just load my app when I tried to access it)

Thanks!

use on scrolling console like output

I am displaying console output to trace logs and would like to use to plugin to scroll to the bottom

However, it doesn't scroll to the bottom. The class output-cmdhas a max-hight set to 300px so there are scrollbars.

    <div>
      <div class='console'>
        <div class='console-inner'>
          <div class='output-cmd' id="cont" v-chat-scroll>
            <pre>
                <code>
                    {{ logarray.join("\n") }}
                </code>
            </pre>
          </div>
        </div>
      </div>
    </div>

UglifyJs Unexpected Token >

After importing vue-chat-scroll, uglifyjs fails in webpack with the following error:

ERROR in js/vendor.3b917c2.js from UglifyJs
SyntaxError: Unexpected token: operator (>) [js/vendor.3b917c2.js:202508,27]

It still runs properly, but it's not able to process it, resulting in huge file sizes.

Scroll methos does not support in Internet explorer 11

I have developed a chat app in laravel and vue js with pusher. It's working proper in all browers but internet explorer is not supporting scroll method. I have installed v-chat-scroll library for scrolling.

Below mentioned errors occuring in console
[Vue warn]: Error in directive chat-scroll inserted hook: "TypeError: Object doesn't support property or method 'scroll'"

Object doesn't support property or method 'scroll'

var scrollToBottom = function scrollToBottom(el, smooth) {
el.scroll({
top: el.scrollHeight,
behavior: smooth ? 'smooth' : 'instant'
});

Here is my package.json file

{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"axios": "^0.16.2",
"bootstrap-sass": "^3.3.7",
"cross-env": "^5.0.1",
"jquery": "^3.1.1",
"laravel-mix": "^1.0",
"lodash": "^4.17.4",
"vue": "^2.1.10"
},
"dependencies": {
"babel-polyfill": "^6.26.0",
"laravel-echo": "^1.4.0",
"pusher-js": "^4.2.2",
"v-toaster": "^1.0.3",
"vue-chat-scroll": "^1.3.3"
}
}

addEventListener is not removed on unbind

although most modern browsers automatically destroy it, older browsers won't and it will cause a memory leak.
ideally we call removeEventListener on unbind in the directive

When i scroll up the chat and send the message it will stay in the position where it was

Procedure of getting problem in scroll
when i open the chat and scroll up and send the message the scroll stay in the position it was .
result needed .
if we scroll up and if we send the message without scrolling chat to bottom . the chat doen't scroll to the bottom automaticall .
if i switch from one chatroom to another chatroom as well the chat is not scrolling to buttom . it is sticking where is stop scrolled
@theomessin sir , is there any solution for it

Scroll position isn't taking into consideration image heights

I've noticed what I think is a weird issue to do with images.

I'm using this in a messaging service and have noticed that it'll scroll to the correct location when all messages are text based, but when messages contain images the scroll position is wrong.

I can only assume this is because it's not taking into consideration the height of the images as these are loading when calcs are run?

Scroll on button click

I used the scroll for a chat.
The chat contains a v-data-table (vuetify), with pagination.
Clicking on the pagination while on the middle of the page, scroll to bottom.
(which I didn't want).
I added a

if (e[0].target.tagName === "BUTTON") {
        return;
      }

inside the scroll directive mutationObserver to deal with it. [be able to interact with an inner element without scrolling].
To specify the issue :
It happens on mouseDown, so the pagination does not take effect, and the page just scroll to bottom.

I guess there might be a better way to handle those kind of things?

Regards,

Require default

Make the following code work:

// ES5
var Vue = require('vue')
Vue.use(require('vue-chat-scroll'))

Scroll bar doesn't go to bottom on route change

my chat routes may change like this - /conversations#/{user_id}
It seems that the scrolling is working fine with a single chat thread.
But when changing the route, scroll bar doesn't go to the bottom.

Scroller is not scrolling to the bottom when content has images

Describe the bug
Scroller is not scrolling to the bottom when content has images.

To Reproduce
Steps to reproduce the behavior:
Add images(medium / large sizes) into vue-chat-scroll

Expected behavior
Completely scroll to bottom

Screenshots
https://prnt.sc/s07c7s

Additional context
This is probably due to vue-chat-scroll initialised before the images are completely loaded

How to change style of message

Hello @theomessin

Thank you for your nice component
Now i am trying to use your component for my chat app.
I want to change style of message inside chat box. In my case,
i want sender and receiver message style are different.
Can you let me know how can i do it ?

Thank you so much

Folder "dist"

Why do you hide this folder from "npm"? I can't use your plugin with your instructions.
Any help will be appreciated. Thanks

Use Vue-chat-scroll with Vuebar

Hello!
Pls tell me how to use vue-chat-scroll with Vuebar?

<template lang="pug">
    div.chat-wrapper
        scroll(id="chat-box" class="messages" v-chat-scroll)
            div(class="chat")
                ul
                    message-bubble(v-for="(msg, index) in messages" :key="index" :sender="msg.personal")
                        img(slot="avatar" :src="msg.avatar")
                        span(slot="date") {{ msg.date }}
                        span(slot="user-name") {{ msg.userName }}
                        p(slot="msg-text") {{ msg.text }}
                    li(style="height: 20px;")


        div.message-box
            input(type="text" class="uk-input" v-model="msgInput" placeholder="Type text...")
            button(class="uk-button uk-button-primary" @click="send") Send
</template>

<script>
import Vue from 'vue'
import MessageBubble from './chat/MessageBubble'
import Scroll from './utils/Scroll'
import VueChatScroll from 'vue-chat-scroll'
Vue.use(VueChatScroll)
</script>

I get such errors

Property or method "v" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.

Property or method "chat" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.

Property or method "scroll" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.

Screenshot-from-2018-06-03-22-21-101d0adeced847f510.png

if I do so
scroll(id="chat-box" class="messages" v-chat-scroll="{always: true}")
That errors disappear, but automatic scrolling does not work

If I do not use Vuebar then automatic scrolling works well.
What do I need to do to solve my problem?

The scroll component looks like this

<template lang="pug">
    div(v-bar="{useScrollbarPseudo: true}")
        slot
</template>

<script>
import Vue from 'vue'
import Vuebar from 'vuebar'

Vue.use(Vuebar)
export default {
  name: 'scroll'
}
</script>

If I open multiple chat window div it scroll always the first one unnecessarily

I have a facebook like chat system. When I open new chat window, it always scroll again the first window. But it works for all chat window if I send message. Another problem is, how can I scroll by default at the bottom of the div without needing to send a new message? Is there any way to apply this scroll programmatically? It seems, scrolling is applied in updated/watch that's why when data changes it runs. I am not sure. :)
Thank you

Scroll on Initialization

Hi, thanks for your work on this plugin.

I was wondering if it's possible to have the plugin scroll to bottom on initialization? Picture a chat window that already has many chats. Often times, you want to pick up at the most recent part of conversation. And having to scroll down, or wait for new message to scroll is not ideal. Does that make sense?

Tidy up configuration

Currently the configuration naming is all over the place. Would ideally refactor this to have all values make sense as a group.

Forked project and add new feature: emit loading events when scroll to the top

Hi theomessin ,
Thanks for the useful vue directive project. I forked your project and modified a little bit to add new feature.
When scroll to the top of element, directive would emit 'scroll-top' event.
This would woks more like a chat box situation.
Here is my jsfiddle demonpm package.
It's my first time to fork others project and republish by myself.
If I do something wrong, please let me and I would fix ASPA.
Thanks again.

Add the ability to disable scrolling

Please, add new property like enabled that true by default.
For example:

const vChatScroll = {
  bind: (el, binding) => {
    let scrolled = false;

    el.addEventListener('scroll', e => {
      scrolled = el.scrollTop + el.clientHeight + 1 < el.scrollHeight;
    });

    (new MutationObserver(e => {
      let config = binding.value || {};
      let pause = config.always === false && scrolled;
      if(!config.enabled) {
         return;
      }
      if (config.scrollonremoved) {
        if (pause || e[e.length - 1].addedNodes.length != 1 && e[e.length - 1].removedNodes.length != 1) return;
      } else {
        if (pause || e[e.length - 1].addedNodes.length != 1) return;
      }
      scrollToBottom(el, config.smooth);
    })).observe(el, { childList: true, subtree: true });
  },
  inserted: scrollToBottom
};

Scroll on page load

Hello,

Just another issue I've come across, would it be possible to make the div scroll to the bottom on page load, as I am now showing some older messages.

Thanks.

@v-chat-scroll-top-reached not working

Describe the bug
When scroll reach to the top @v-chat-scroll-top-reached event must trigger. But its not working

<v-list
v-chat-scroll="{ always: false, smooth: true }"
@v-chat-scroll-top-reached="customMethod"
class="overflow-y-auto"
height="500"

  >

methods: {
customMethod() {
console.log('reach');

},

transition-group not supported

Describe the bug
If dynamic elements are wrapped by a transition-group element in order to enable custom enter & exit transitions, the directive does not work. When put on the element around the transition-group, it properly scrolls the div down on first open of the page, but fails to register element additions — the scroll to bottom doesn't happen. If put on the transition-group element itself, even with tag set to div, none of the intended functionality works.

I may attempt fixing this in the next days myself, if you're interested, just lemme know!

To Reproduce
Steps to reproduce the behavior:

  1. add the directive on a container that wraps a transition-group element containing a dynamic list of elements.

Expected behavior
The directive behaves exactly as without a transition-group.

Scrolling not working if messages are covered with container

Describe the bug
My problem and solution are clearly described here: https://stackoverflow.com/questions/50455751/vue-chat-scroll-doesnt-work-with-a-loader

A working demo reproducing the problem: https://jsfiddle.net/StpFlp_DDK/6s0kbtkr/

Why it is matter
In my case, I have a distinct categories for read and unread messages, each having separate container. And when new unread messages arrive, they attached to the unread messages container. Thus, the change in elements count is not detected now and scrolling is not working in this case. I think it is a common practice to split chat messages into categories or groups, not extactly into read and unread, but maybe groupping them by send date, and if new message arrived e.g. not later than 5 minute after last one, it is attached to last group. Or consider groupping by sender. Just look at any modern IM, like Telegram, WhatsApp, etc.. - they all use some or even several types of groupping messages at once.

Can't get it to work in Firefox

Works in Chrome though.

Firefox: 62.0.3 (64-bit)
vue: 2.5.17
vue-chat-scroll: 1.3.3

When I load the page, the container is just as big as the total amount of messages in chat, exceeding the viewport. No scrollbar appears. I'm using the readme.md example with { always: false }.

Failed to resolve directive: chat-scroll - vue v. 2.2.6

I use:
in mail.js

import Vue from 'vue'
import VueChatScroll from 'vue-chat-scroll';
Vue.use(VueChatScroll);

in component:

<div v-chat-scroll="config">
  <div v-for="(comment, key) in comments">
    ...
  </div>
</div>

...
 config: {
  always: true
 }
...

And i have error

[Vue warn]: Failed to resolve directive: chat-scroll 
(found in <Anonymous> - use the "name" option for better debugging messages.)

el.scroll is not a function

I am getting this error:
TypeError: el.scroll is not a function

Does this plugin require jQuery? If yes, it should by mentoied in readme.

Use semantic release to automate releasing

Requires commit messages to conform to conventional commits. All pull requests will point to a release branch (master or next for pre-releases) and should only implement a single feature/patch. These will be rebased and semantic release will take care of running npm run build and publishing the new version.

Instant scrolling doesn't work on initial load

When I open the component I guess smooth scrolling, even tho it's disabled. When I get other message it is instant but not on load.

I guess it's because in inserted, it doesn't check for the configs.

Thanks !

Edge does not support el.scroll

In the scrollToBottom method, there is a call to el.scroll. When el is an Element, it works fine on Chrome and Firefox but not on Edge.

I'm not sure the root cause of this, but I believe el.scroll should be avoided entirely. Edge throws an error, but I don't see scroll in Element's properties whatsoever: https://developer.mozilla.org/en-US/docs/Web/API/Element

Replacing scroll with a documented method like scrollTop would likely increase compatibility.

vue-chat-scroll is scrolling to the wrong position

I have the following structure

<div class="messages">
   <div class="s-box" v-chat-scroll>
        <v-component v-for="m in messages"/>
   </div>
</div>

.messages {
 display: flex;
 flex: auto;
 flex-direction: column;
}

s-box {
 margin-top: auto;
}

when I use this code, the wrapper's scroll scrolls to the correct position and scroll to a wrong position, its this because of the component used?

how to use this programatically? or scroll on event ?

I can't get it to work in my project. When I initially load my chatrooms they are empty of messages, then another API call gets the messages and fills up the wrapper div on which v-chat-scroll is applied

I would want it to auto-scroll to the bottom at that point.. but it doesn't happen

How can I fire a "scroll to bottom" after I get the response from my api call ?

Add event when top of scrollbar is reached

Is your feature request related to a problem? Please describe.
When a client is entering my chat, I'm only showing to him the recent messages. If he would like to see now also further messages, then he needs to scroll up to the beginning, where further should be fetched asynchronously.

Describe the solution you'd like
An event would be nice that is automatically triggered when user scrolls up and reaches the top of the scrollbar

vue-chat-scroll doesn't work

I'm using vue with laravel. This is where i include module.

require('./bootstrap');

window.Vue = require('vue');

import VueChatScroll from 'vue-chat-scroll'
import VeeValidate from 'vee-validate'

const config = {
    errorBagName : 'ferrors'
}

Vue.use(VeeValidate,config);
Vue.use(VueChatScroll);

Vue.component('chat-component', require('./components/ChatComponent.vue'));
const app = new Vue({
    el: '#app',

});

In my chat-component i registerer messages component. Message component code with v-chat-scroll setted:

<template>

    <ul class="chat" v-chat-scroll>
        <li v-bind:class="['clearfix', (message.admin) ? 'left' : 'right']"  v-for="message in messages"><span v-bind:class="['chat-img', (message.admin) ? 'pull-left' : 'pull-right']">
                            <img :src="[(message.admin) ? 'http://placehold.it/50/55C1E7/fff&text=U' : 'http://placehold.it/50/FA6F57/fff&text=ME']"   alt="User Avatar" class="img-circle" />
                        </span>
            <div class="chat-body clearfix">
                <div class="header">
                    <strong v-bind:class="['primary-font', (!message.admin) ? 'pull-right' : '']">Jack Sparrow</strong> <small v-bind:class="['text-muted', (message.admin) ? 'pull-right' : '']" v-text="sentOn(message)">
                    <span class="glyphicon glyphicon-time"></span></small>
                </div>
                <p v-text="message.body" v-bind:class="message.admin ? 'pull-left' : 'pull-right' "></p>
            </div>
        </li>

    </ul>

</template>

And it's not working. I can't figure out what am I doing wrong.

Make it working with disappearing elements

Hey, first thanks for this package. I am using for my chat interface and mostly it works great.
A problem I have is when I use a typing indicator(animated bubble). It is shown while messages are coming in but it disappears afterward. I think this change conflicts with your package because the scrolling is wrong now. It scrolls further down that it should be, resulting in some whitespace under the last message. When I move the mouse, then it automatically scrolls up, realizing there is nothing after the last message. Do you know of any solution to get this working for me?

Here are some images explaining my case:

  1. Showing typing indicator
    screenshot1

  2. Showing wrong scroll position
    screenshot1

  3. Showing correct scroll position after I move the mouse
    screenshot1

Keep focus on previous item when prepending items to the list

Is your feature request related to a problem? Please describe.
Last week I've created the pull request for the event @v-chat-scroll-top-reached, which works fine.
When I'm prepending new items to the list, then the position of the scrollbar still remains on top.
Instead the focus should be kept on the previous item that was on top.

Do you have suggestions how we can solve this problem?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.