Skip to content

Unable to have vue component as tag #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
michaeldtruong opened this issue Jan 31, 2021 · 12 comments
Open

Unable to have vue component as tag #11

michaeldtruong opened this issue Jan 31, 2021 · 12 comments

Comments

@michaeldtruong
Copy link

(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.

@David-Desmaisons
Copy link
Member

Try
tag="CanvasElementsDragTag"

@michaeldtruong
Copy link
Author

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

@entioentio
Copy link

entioentio commented Mar 28, 2021

+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!

@upupzealot
Copy link

+1 any solution here?

@David-Desmaisons
Copy link
Member

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

@michaeldtruong
Copy link
Author

@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.

@cihadturhan
Copy link

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.

vuejs/core#815 (comment)

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

@WormGirl
Copy link

WormGirl commented Feb 18, 2022

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

@GeraldGallet
Copy link

GeraldGallet commented Mar 16, 2022

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>

@WormGirl
Copy link

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.

@shy1118999
Copy link

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

@nathanwalasek
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants