Skip to content

Commit 4ca3fdd

Browse files
committed
Improvement - VueUiDashboard - Prevent dashboard events when using range inputs in components
1 parent 89c17f3 commit 4ca3fdd

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

src/components/vue-ui-dashboard.vue

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ function toggleLock() {
3030
}
3131
3232
const gridSize = 20;
33-
const items = ref(props.dataset);
33+
const items = ref(props.dataset.map((item,i) => {
34+
return {
35+
...item,
36+
index: i
37+
}
38+
}));
3439
const dragging = ref(null);
3540
const resizing = ref(null);
3641
const dragStart = ref({ x: 0, y: 0 });
@@ -39,6 +44,22 @@ const dashboardContainer = ref(null);
3944
const isDragOrResize = ref(false);
4045
const changeIndex = ref(null);
4146
const isPrinting = ref(false);
47+
const isPaused = ref(false);
48+
49+
function handleInteraction(event) {
50+
const target = event.target;
51+
if (target.tagName === "INPUT" && target.type === "range") {
52+
isPaused.value = true;
53+
}
54+
}
55+
56+
function handleInteractionEnd(event) {
57+
const target = event.target;
58+
if (target.tagName === "INPUT" && target.type === "range") {
59+
isPaused.value = false;
60+
}
61+
}
62+
4263
4364
function generatePdf(){
4465
isPrinting.value = true;
@@ -127,7 +148,7 @@ function checkDirection(item, deltaX, deltaY) {
127148
}
128149
129150
function onMouseMove(event) {
130-
if (isLocked.value) return;
151+
if (isLocked.value || isPaused.value) return;
131152
isDragOrResize.value = true;
132153
if (dragging.value !== null) {
133154
const item = items.value[dragging.value];
@@ -182,7 +203,7 @@ function stopDragResize() {
182203
};
183204
184205
function onTouchStart(index) {
185-
if (isLocked.value) return;
206+
if (isLocked.value || isPaused.value) return;
186207
isDragOrResize.value = true;
187208
changeIndex.value = index;
188209
if (resizing.value === null) {
@@ -214,7 +235,7 @@ function onTouchResizeMove(event) {
214235
};
215236
216237
function onTouchMove(event) {
217-
if (isLocked.value) return;
238+
if (isLocked.value || isPaused.value) return;
218239
isDragOrResize.value = true;
219240
event.preventDefault();
220241
if (dragging.value !== null) {
@@ -280,7 +301,12 @@ defineExpose({
280301
</script>
281302

282303
<template>
283-
<div>
304+
<div
305+
@mousedown="handleInteraction"
306+
@mouseup="handleInteractionEnd"
307+
@touchstart="handleInteraction"
308+
@touchend="handleInteractionEnd"
309+
>
284310
<div data-html2canvas-ignore style="width: 100%; display:flex; justify-content: end;" v-if="FINAL_CONFIG.allowPrint">
285311
<button class="vue-ui-dashboard-button" @click="generatePdf" :disabled="isPrinting" style="margin-top:12px" :style="`color:${FINAL_CONFIG.style.board.color}`">
286312
<svg class="vue-ui-dashboard-print-icon" xmlns="http://www.w3.org/2000/svg" v-if="isPrinting" width="20" height="20" viewBox="0 0 24 24" stroke-width="1.5" :stroke="FINAL_CONFIG.style.board.color" fill="none" stroke-linecap="round" stroke-linejoin="round">
@@ -316,11 +342,11 @@ defineExpose({
316342
top: `${item.top}%`,
317343
cursor: 'move',
318344
boxShadow: changeIndex === index ? '0 6px 12px -3px rgba(0,0,0,0.3)' : '',
319-
zIndex: changeIndex === index ? '1' : '0',
345+
zIndex: changeIndex === index ? items.length + 1 : item.index,
320346
backgroundColor: FINAL_CONFIG.style.item.backgroundColor
321347
}"
322348
@mousedown="startDrag(index)"
323-
@touchstart="onTouchStart(index)"
349+
@touchstart="onTouchStart(index, item)"
324350
>
325351
<template v-if="!isLocked">
326352
<div
@@ -352,6 +378,7 @@ defineExpose({
352378
@touchend="onTouchEnd"
353379
></div>
354380
</template>
381+
355382
<slot name="content" :item="item" :index="index" :left="item.left" :top="item.top" :height="item.height" :width="item.width"></slot>
356383
</div>
357384
</div>

0 commit comments

Comments
 (0)