-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Suggestion: Allow placeholder when target array is empty #480
Comments
In terms of API, using a named slot would totally makes senses. I like this proposal. |
It would be convenient to be able to add this placeholder anywhere, not just inside of the target list, and make its disappearance optional, so it also addresses #457 more adequately. |
I would also second this, especially for nested components. |
Any news on this? @David-Desmaisons has this made it into your roadmap for a future version? |
@madebycaliper still have no good idea on how to implement such a feature. I should not be abble to deliver it in the short/mid term. |
@David-Desmaisons thanks for the reply. it seems like a complex feature! |
Think out of the box. You have VUE at hand :-)
(Ok you need a dummy key 4711.) |
@dominiczaq Well your sample is exactly an example that IS NOT WORKING, because vue.draggable needs the inner children to map the list |
@Doogiemuc yea, I've implemented a working solution a number of times, as I use this component in a bunch of projects and had to figure it out. But I think having something standardized that's built into the component itself would make it easier to implement and more future-proof |
@madebycaliper what is your work-around? |
@David-Desmaisons I have a solution that works with some glitches listArray: this.cardList, cardList() { if you have an empty list the function cardList in computed return an empty list for you to enter the cards in to. that fixed most of the bugs for me |
I totally agree with madebycaliper: There should be a standard solution in Vue.draggable. |
@Doogiemuc I agree. Still looking for a reliable solution. |
@David-Desmaisons I often use Vuex to fire a
There are oviously lots of custom tactics available, but it would be great if you offered a standardized solution and some supporting logic. @SirLamer I definitely like the idea of a named slot, as it would be optional and unobtrusive. If the Draggable component could just conditionally show that slot based on |
I have had some success using the header slot like this as the last element inside the draggable component: |
I agree that a named slot would be ideal. However, here's my v simple workaround that's bug free (for me) :
This works with
|
N.B. above doesn't seem to work when using a transition-group as this adds a span to the "empty" list, meaning the :empty selector doesn't get applied. |
I got transition-group working with modified css selector and tag="div" as per :
i.e. add a second selector to target the empty div produced by the transition-group Hope that helps someone out, and thanks for the awesome code ! |
Any updates? |
@David-Desmaisons this issue was first raised more than 3 years ago. It doesn't seem like an overly complicated problem to generate/create a cloned copy of the item that is being dragged and have it stay in the original position in the list. A cloned (ghost) version is already being created, but it's being moved around depending on the mouse position. So another non-moving clone can be created to remain in place where the original item used to sit. This will make sorting items in the list much calmer to look at as there won't be so much movement happening during the sorting of the item, and it would also fix the webkit hover bug which applies the hover class onto items that are positioned instead of the original item that's being dragged. |
+1 for this. This is the feature am working on where i want to have a bigger drag area Skaermoptagelse.2022-01-01.kl.23.59.37.mov |
I found a workaround for this webkit browsers bug. For every draggable element you need to add mouseover events which take setHoverEffect function. setHoverEffect (event) {
const childList = [].slice.call(event.currentTarget.parentElement.children)
for (const child of childList) {
child.classList.remove('hovered')
}
if( !childList.some((child) => child.classList.contains('sortable-chosen')) ) {
event.currentTarget.classList.add('hovered')
}
} .hovered {
background-color: orange;
color: #fff;
} Then you need to add mouseleave event which will remove hovered class. |
is this project still active? I see no resolution for this issue, so I'm assuming no? |
I found a CSS solution: In case you have a header or footer already use |
Any updates? |
How about doing this. <Draggable class="list-group" :list="list" group="blocks" item-key="uuid">
<template #header v-if="draft.length == 0">
What you want to show when the list is empty
</template>
<template #item="{ element, index }">
Your list
</template>
</Draggable> This essentially hides the header slot when the list has more than 0 elements. |
Any updates on this? |
Just an idea... it would be swell to be able to allow placeholder, perhaps provided as a named slot, which is displayed only when the target array is empty. As soon as an item is dragged in to the 'draggable' field, even before released, the placeholder is no longer rendered. This would appear like the first element being added is going to replace the placeholder upon release.
So one can imagine a note like "drop here to add things" with an infographic icon being in place of nothingness. This secondarily resolves the issue of maintaining a minimum height of the HTML element to allow use when empty.
This past issue discusses a similar need:
#335
The text was updated successfully, but these errors were encountered: