Skip to content

Commit 92ca8ac

Browse files
committed
add disabled option
1 parent eab58b5 commit 92ca8ac

File tree

2 files changed

+28
-19
lines changed

2 files changed

+28
-19
lines changed

src/components/SwipeList.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
v-for="(item, index) in items"
55
:key="item[transitionKey] || index"
66
:ref="`list-item-${index}`"
7+
:disabled="disabled"
78
class="swipeout-list-item"
89
@swipeout:click="_emitClick($event, item, index)"
910
@swipeout:dobuleclick="_emitDblClick($event, item)"
@@ -39,9 +40,9 @@
3940
type: String,
4041
default: 'id',
4142
},
42-
transitionString: {
43-
type: String,
44-
default: 'swipe-list-item',
43+
disabled: {
44+
type: Boolean,
45+
default: false,
4546
},
4647
},
4748
methods: {

src/components/SwipeOut.vue

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div class="swipeout"
3-
:class="{'swipeout--transitioning' : isTransitioning}">
3+
:class="{'swipeout--transitioning' : isTransitioning, 'swipeout--disabled': disabled}">
44
<div v-if="hasLeft" class="swipeout-left" ref="left">
55
<slot name="left"></slot>
66
</div>
@@ -48,7 +48,11 @@
4848
threshold: {
4949
type: Number,
5050
default: 45,
51-
},
51+
},
52+
disabled: {
53+
type: Boolean,
54+
default: false,
55+
}
5256
},
5357
mounted() {
5458
if (!this.hasLeft && !this.hasRight)
@@ -87,22 +91,13 @@
8791
this.rightOpen = true;
8892
this._animateSlide(-this.rightActionsWidth, oldLeft);
8993
},
90-
clickReveal() {
91-
if (!this.hasLeft && this.hasRight)
92-
if (this.rightOpen)
93-
this.closeActions();
94-
else
95-
this.revealRight();
96-
if (this.hasLeft && !this.hasRight)
97-
if (this.leftOpen)
98-
this.closeActions();
99-
else
100-
this.revealLeft();
101-
},
10294
// private
10395
_createHammer() {
10496
this.hammer = new Hammer.Manager(this.$el, {
10597
touchAction: 'pan-y',
98+
cssProps: {
99+
userSelect: '',
100+
},
106101
});
107102
108103
const doubelTab = new Hammer.Tap({ event: 'doubletap', taps: 2 });
@@ -131,6 +126,9 @@
131126
return contentRect.left - elementRect.left;
132127
},
133128
_startListener(event) {
129+
if (this.disbaled)
130+
return null;
131+
134132
this.isTransitioning = false;
135133
if (event.deltaY >= -5 && event.deltaY <= 5) {
136134
this.leftActionsWidth = this.$refs.left ? this.$refs.left.clientWidth : 0;
@@ -148,7 +146,7 @@
148146
this.closeActions();
149147
},
150148
_swipeListener(event) {
151-
if (!this.isActive)
149+
if (!this.isActive || this.disabled)
152150
return null;
153151
154152
const newX = this.startLeft + event.deltaX;
@@ -180,7 +178,7 @@
180178
return this._animateSlide(newX);
181179
},
182180
_stopListener(event) {
183-
if (!this.isActive)
181+
if (!this.isActive || this.disabled)
184182
return null;
185183
186184
const oldLeft = this.$refs.content.getBoundingClientRect().left;
@@ -260,12 +258,18 @@
260258
});
261259
},
262260
_singleTap(e) {
261+
if (this.disabled)
262+
return;
263263
this.$emit('swipeout:click', e);
264264
},
265265
_doubleTap(e) {
266+
if (this.disabled)
267+
return;
266268
this.$emit('swipeout:dobuleclick', e);
267269
},
268270
contentClick(e) {
271+
if (this.disabled)
272+
return;
269273
this.$emit('swipeout:contentclick', e);
270274
},
271275
},
@@ -279,6 +283,10 @@
279283
display: flex;
280284
}
281285
286+
.swipeout.swipeout--disabled {
287+
user-select: auto;
288+
}
289+
282290
.swipeout .swipeout-left, .swipeout .swipeout-right {
283291
position: absolute;
284292
height: 100%;

0 commit comments

Comments
 (0)