phphe / vue-draggable-nested-tree

Vue2 draggable tree component
https://hetree.phphe.com/
MIT License
345 stars 61 forks source link

Nodes flicker when dragging #74

Open rabbitfufu opened 5 years ago

rabbitfufu commented 5 years ago

One problem I have come across is that the tree 'flickers' when dragging nodes, which can be visually confusing, especially with large data sets, or when dragging multiple nested nodes.

The flicker happens because, when the placeholder is rendered, the old placeholder and the new placeholder co-exist for a split second, pushing all of the nodes in the tree down the height of the double placeholders.

In my own code that uses this component, I have fixed this problem with the following workaround...

<template>
    <Tree :data='treeData' draggable>
        <div slot-scope='{data, store}'>
            <template v-if='!data.isDragPlaceHolder'>
                ...
            </template>
            <template v-else>{{killGhostPlaceholder()}}</template>
        </div>
    </Tree>
</template>

<script>
    export default {
        ...
        methods: {
            killGhostPlaceholder() {
                const placeholders = this.$el.querySelectorAll('.draggable-placeholder')
                if (placeholders.length) placeholders[0].style.display = 'none'
            }
        }
    }
</script>

This quickly hides any pre-existing placeholders before a new placeholder is rendered.

It's a bit of bandage patch, but it seems to work, so maybe this will be useful...

phphe commented 5 years ago

thanks. I will check it.