Skip to content

item slot must have only one child #165

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
90ker opened this issue Jul 24, 2022 · 7 comments
Open

item slot must have only one child #165

90ker opened this issue Jul 24, 2022 · 7 comments

Comments

@90ker
Copy link

90ker commented Jul 24, 2022

When i put a code comment in the Draggable component slot, it will throw error.
image
image

@90ker
Copy link
Author

90ker commented Jul 24, 2022

I think the comments shouldn't be include.

@LiuJinYang9527
Copy link

same issue

@cschra
Copy link

cschra commented Aug 11, 2022

you have to use the name element or else it is not working correctly - I created a PR (#171) to add this to the docs.
if you want to use a custom variable name you can do #item="{ element: item }"

@agardes
Copy link

agardes commented Aug 4, 2023

It considers your comment to be part of the div. I had the same issue and deleting the comment fixed it.

@albadedan
Copy link

albadedan commented Sep 6, 2023

you have to use the name element or else it is not working correctly - I created a PR (#171) to add this to the docs. if you want to use a custom variable name you can do #item="{ element: item }"

I am using the name element but I still get the bug.

(A) Works

<draggable
  v-model="someArray"
  group="someGroup"
  @start="drag = true"
  @end="drag = false"
  item-key="id">
      <template #item="{element}">
          <v-row>
              <v-col>{{ element.id }}</v-col>
              <v-col>{{ element.name }}</v-col>
          </v-row>
      </template>
</draggable>

(B) Does not work
Produces Error: Item slot must have only one child

<draggable
  v-model="someArray"
  group="someGroup"
  @start="drag = true"
  @end="drag = false"
  item-key="id">
      <template #item="{element}">
          <!-- some comment  -->
          <v-row>
              <v-col>{{ element.id }}</v-col>
              <v-col>{{ element.name }}</v-col>
          </v-row>
      </template>
</draggable>

(C) Also does not work, but in a different way
Does not produce the error, but does not render anything

<draggable
  v-model="someArray"
  group="someGroup"
  @start="drag = true"
  @end="drag = false"
  item-key="id">
      <template #item="{element}">
          <template>
              <!-- some comment  -->
              <v-row>
                  <v-col>{{ element.id }}</v-col>
                  <v-col>{{ element.name }}</v-col>
              </v-row>
          </template>
      </template>
</draggable>

(D) Does work, renders just like (A)

<draggable
  v-model="someArray"
  group="someGroup"
  @start="drag = true"
  @end="drag = false"
  item-key="id">
      <template #item="{element}">
          <div>
              <!-- some comment  -->
              <v-row>
                  <v-col>{{ element.id }}</v-col>
                  <v-col>{{ element.name }}</v-col>
              </v-row>
          </div>
      </template>
</draggable>

I'm using Vuetify, so v-container, v-card, etc, also work instead of div.

@trry-hub
Copy link

因为注释也被当成了元素

@rachitpant
Copy link

Its not just the comments. There are valid use cases where one "item" from model can result in two "children" inside the slot.

See the screenshot below that shows old code that worked , and with this new vue 3 library , it doesn't work. ( because of the two tr's inside the slot , it complains item slot must have only one child )
We are sometimes creating two rows based on the condition , so there are actually two children inside the slot. ( see the two trs )

Image

See below , there were 12 "items" passed to draggable , but 13 actual rows. ( A blank row was created conditionally after row 3 ). This worked perfectly in the old library , not anymore after upgrading to vue 3. There is no draggable-handle in the extra row , so it can't anyways be dragged.

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

7 participants