Skip to content

Commit 225e1f6

Browse files
Vivere Disceremarcosmoura
authored andcommitted
fix ripple effect on touchscreen desktops (vuematerial#479)
1 parent 56aeaff commit 225e1f6

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

src/core/components/mdInkRipple/mdInkRipple.vue

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,23 @@
77
<style lang="scss" src="./mdInkRipple.scss"></style>
88

99
<script>
10-
const hasTouch = 'ontouchstart' in document;
11-
const getEventName = (type) => {
10+
const addEvent = (target, type, handler) => {
1211
if (type === 'start') {
13-
return hasTouch ? 'touchstart' : 'mousedown';
12+
target.addEventListener('mousedown', handler);
13+
target.addEventListener('touchstart', handler);
14+
} else {
15+
target.addEventListener('mouseup', handler);
16+
target.addEventListener('touchend', handler);
1417
}
15-
16-
return hasTouch ? 'touchend' : 'mouseup';
17-
};
18-
const addEvent = (target, type, handler) => {
19-
target.addEventListener(getEventName(type), handler);
2018
};
2119
const removeEvent = (target, type, handler) => {
22-
target.removeEventListener(getEventName(type), handler);
20+
if (type === 'start') {
21+
target.removeEventListener('mousedown', handler);
22+
target.removeEventListener('touchstart', handler);
23+
} else {
24+
target.removeEventListener('mouseup', handler);
25+
target.removeEventListener('touchend', handler);
26+
}
2327
};
2428
2529
export default {
@@ -135,6 +139,18 @@
135139
removeEvent(document.body, 'end', this.endRipple);
136140
},
137141
startRipple(event) {
142+
if (event.type === 'touchstart') {
143+
this.previous.push('touch');
144+
} else {
145+
this.previous.push('mouse');
146+
}
147+
148+
this.previous = this.previous.splice(this.previous.length - 2, this.previous.length);
149+
150+
if (this.previous.length >= 2 && this.previous[1] === 'touch' && this.previous[0] === 'mouse') {
151+
return;
152+
}
153+
138154
this.clearState();
139155
this.awaitingComplete = window.setTimeout(() => {
140156
this.hasCompleted = true;
@@ -169,6 +185,7 @@
169185
init() {
170186
this.rippleElement = this.$el;
171187
this.parentElement = this.getClosestPositionedParent(this.$el.parentNode);
188+
this.previous = ['mouse'];
172189
173190
if (!this.parentElement) {
174191
this.$destroy();

0 commit comments

Comments
 (0)