vue.draggable.next icon indicating copy to clipboard operation
vue.draggable.next copied to clipboard

Unable to have vue component as tag

Open michaeldtruong opened this issue 4 years ago • 12 comments

(using 4.0.1) I am unable to use a component as the 'tag'. The component itself is registered globally

main.js import CanvasElementsDragTag from '@/app/components/CanvasElementsDragTag'; app.component('CanvasElementsDragTag', CanvasElementsDragTag);

CanvasElementsDragTag.vue

<template>
  <div></div>
</template>

<script>
export default {
  setup() {
    console.log('in');
  }
}
</script>

CanvasElements.vue

  <draggable
    v-model="computedList"
    item-key="id"
    @choose="handleChoose"
    @start="handleStart"
    @end="handleEnd"
    :group="group"
    :animation="150"
    :swap-threshold="0.7"
    :invert-swap="true"
    :fallback-on-body="true"
    :set-data="setData"
    tag="canvas-elements-drag-tag"
  >
    <template #item="{element}">
      <component 
        @mouseover="ev => ev.stopPropagation()"
        :is="element.elementType" 
        :data="element"
      />
    </template>
  </draggable>

I am able to see 'in' in the console but get this error after

Screen Shot 2021-01-31 at 2 06 26 PM

Not sure if there is something obvious I am missing.

michaeldtruong avatar Jan 31 '21 19:01 michaeldtruong

Try tag="CanvasElementsDragTag"

David-Desmaisons avatar Jan 31 '21 19:01 David-Desmaisons

Its one of the things I already tried, no dice same error =(

michaeldtruong avatar Jan 31 '21 20:01 michaeldtruong

+1 Uncaught (in promise) TypeError: Cannot set property '__draggable_context' of null I get this when creating new item on the list. Thanks for the workaround of using a html tag as a wrapper!

entioentio avatar Mar 28 '21 22:03 entioentio

+1 any solution here?

upupzealot avatar Apr 03 '21 18:04 upupzealot

@michaeldtruong Make sure that you register the component in the same app instance where you instanciate the draggable component.

David-Desmaisons avatar Jun 10 '21 23:06 David-Desmaisons

@David-Desmaisons Thanks for the suggestion, I ended up changing my implementation so I don't need to get this working anymore. I did take a second look into this yesterday to close the issue but it seems that it was not what was causing the error. I will revisit this in the future to see what is it with my implementation that is causing it to not work properly.

michaeldtruong avatar Jun 15 '21 13:06 michaeldtruong

I'm having the same error. Uncaught (in promise) TypeError: Cannot set property '__draggable_context' of null

Looks like it returns null from the slot el in componentStructure.js

const getHtmlElementFromNode = ({ el }) => el;
// ...
// ...
updated() {
    const { defaultNodes, realList } = this;
    defaultNodes.forEach((node, index) => {
      addContext(getHtmlElementFromNode(node), {
        element: realList[index],
        index
      });
    });
  }

Did some research. Evan You had a comment about it:

You should not be relying on vnode.el in userland code. It's not documented public API and there is no guarantee about what the "expected behavior" is. The documented public API for accessing mounted DOM is via template refs.

https://github.com/vuejs/vue-next/issues/815#issuecomment-597736026

I believe the implementation logic should change based on this comment.

cihadturhan avatar Dec 06 '21 13:12 cihadturhan

I have the same problem.

// component
<template>
  <draggable
    :list="list"
    :item-key="itemKey"
    tag="transition-group"
    :component-data="{
      name: typeDrag ? null : 'flip-list'
    }"
    @start="typeDrag = true"
    @end="typeDrag = false"
    :animation="200"
    ghost-class="ghost"
    :group="group"
  >
    <template #item="data">
      <slot name="item" v-bind="data"></slot>
    </template>
  </draggable>
</template>

//  other file to use
<DraggableBox :list="typeList" item-key="value" group="type">
          <template #item="{ element }">
            <div class="lc-drag">
              <svg class="icon lc-dragbar" aria-hidden="true">
                <use xlink:href="#icon-vm-drag"></use>
              </svg>
              <ACheckbox :value="element.value">
                {{ element.name }}
              </ACheckbox>
            </div>
          </template>
        </DraggableBox>

image

WormGirl avatar Feb 18 '22 02:02 WormGirl

Hey @WormGirl, I recently had the same issue but with a <component /> tag. What worked for me was wrapping it in a <div></div> tag. The documentation says your template should only have one child element, and I think the <draggable> tries to read the DOM to get this child element, but with a <slot /> or <component /> it doesn't manage to do so. So your solution here would be :

<draggable
    :list="list"
    :item-key="itemKey"
    tag="transition-group"
    :component-data="{
      name: typeDrag ? null : 'flip-list'
    }"
    @start="typeDrag = true"
    @end="typeDrag = false"
    :animation="200"
    ghost-class="ghost"
    :group="group"
  >
    <template #item="data">
      <div>
        <slot name="item" v-bind="data"></slot>
      </div>
    </template>
  </draggable>

GeraldGallet avatar Mar 16 '22 08:03 GeraldGallet

Hey @WormGirl, I recently had the same issue but with a <component /> tag. What worked for me was wrapping it in a <div></div> tag. The documentation says your template should only have one child element, and I think the <draggable> tries to read the DOM to get this child element, but with a <slot /> or <component /> it doesn't manage to do so. So your solution here would be :

<draggable
    :list="list"
    :item-key="itemKey"
    tag="transition-group"
    :component-data="{
      name: typeDrag ? null : 'flip-list'
    }"
    @start="typeDrag = true"
    @end="typeDrag = false"
    :animation="200"
    ghost-class="ghost"
    :group="group"
  >
    <template #item="data">
      <div>
        <slot name="item" v-bind="data"></slot>
      </div>
    </template>
  </draggable>

You are right, i resolved it by this too.

WormGirl avatar Mar 16 '22 12:03 WormGirl

I had the same problem when I upgraded all the dependencies.

shy1118999 avatar Jun 04 '22 09:06 shy1118999

I had the same problem when I upgraded all the dependencies.

Were you able to resolve your issue? I ran updates on packages and only recently discovered that Draggable with transition-group tag is no longer working.

image

nathanwalasek avatar Jun 15 '22 19:06 nathanwalasek