For some reason, draggable isn't disabling text selection on the longer input, so you can disable it yourself. Do that using a CSS class and the pointer-events
property:
.noselect {
pointer-events: none;
}
Use a boolean to toggle this class on all inputs:
data: () => ({
lock: false // This will toggle a class on all textboxes
...
}
Use mousedown
, mouseup
, and blur
events to manage the toggle and apply the noselect
class when lock
is true
:
<input type="text"
v-model="element"
@mousedown="lock = true"
@mouseup="lock = false"
@blur="lock = false"
:class="{ noselect: lock }"
/>
Here's a demo:
var app = new Vue({
el: '#app',
data: () => ({
lock: false,
drag: false,
myArray:["This one drags ok","This one too","Well, this one too","and this","Everything else drags except inputs that have string longer than the element size"],
message: 'Hello Vue!'
})
})
.noselect {
pointer-events: none;
}
<div id="app">
<draggable
v-model="myArray"
group="people"
@start="drag=true"
@end="drag=false"
>
<div v-for="element in myArray" :key="element.id">
<input type="text"
v-model="element"
@mousedown="lock = true"
@mouseup="lock = false"
@blur="lock = false"
:class="{ noselect: lock }"
/>
</div>
</draggable>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/Sortable.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Vue.Draggable/2.20.0/vuedraggable.umd.min.js"></script>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…