Skip to content

Commit 156506b

Browse files
VdustRmarcosmoura
authored andcommitted
fix(MdButton): Ripple for firefox (#1468)
* fix(MdButton): Ripple for firefox fix #1461 * refactor(MdButton): new computed `rippleWorks` * refactor(MdButton): active ripple by props instead of method call * refactor(MdButton): remove unnecessary events
1 parent 6860d3a commit 156506b

File tree

3 files changed

+53
-6
lines changed

3 files changed

+53
-6
lines changed

src/components/MdButton/MdButton.vue

+43-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
88
export default new MdComponent({
99
name: 'MdButton',
10+
data () {
11+
return {
12+
rippleActive: false
13+
}
14+
},
1015
components: {
1116
MdButtonContent
1217
},
@@ -23,11 +28,22 @@
2328
disabled: Boolean,
2429
to: null
2530
},
31+
computed: {
32+
rippleWorks () {
33+
return this.mdRipple && !this.disabled
34+
}
35+
},
2636
render (createElement) {
2737
const buttonContent = createElement('md-button-content', {
2838
attrs: {
2939
mdRipple: this.mdRipple,
3040
disabled: this.disabled
41+
},
42+
props: {
43+
mdRippleActive: this.rippleActive
44+
},
45+
on: {
46+
'update:mdRippleActive': active => this.rippleActive = active,
3147
}
3248
}, this.$slots.default)
3349
let buttonAttrs = {
@@ -45,7 +61,33 @@
4561
disabled: this.disabled,
4662
type: !this.href && (this.type || 'button')
4763
},
48-
on: this.$listeners
64+
on: {
65+
...this.$listeners,
66+
touchstart: event => {
67+
if (!this.rippleWorks) {
68+
return false
69+
}
70+
71+
this.rippleActive = event
72+
this.$listeners.touchstart && this.$listeners.touchstart(event)
73+
},
74+
touchmove: event => {
75+
if (!this.rippleWorks) {
76+
return false
77+
}
78+
79+
this.rippleActive = event
80+
this.$listeners.touchmove && this.$listeners.touchmove(event)
81+
},
82+
mousedown: event => {
83+
if (!this.rippleWorks) {
84+
return false
85+
}
86+
87+
this.rippleActive = event
88+
this.$listeners.mousedown && this.$listeners.mousedown(event)
89+
}
90+
}
4991
}
5092
let tag = 'button'
5193

src/components/MdButton/MdButtonContent.vue

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<md-ripple :md-disabled="!mdRipple || disabled">
2+
<md-ripple :md-disabled="!mdRipple || disabled" :md-event-trigger="false" :md-active="mdRippleActive" @update:mdActive="active => $emit('update:mdRippleActive', active)">
33
<div class="md-button-content">
44
<slot />
55
</div>
@@ -16,6 +16,7 @@
1616
},
1717
props: {
1818
mdRipple: Boolean,
19+
mdRippleActive: [Boolean, Event],
1920
disabled: Boolean
2021
}
2122
}

src/components/MdRipple/MdRipple.vue

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<template>
22
<div
33
:class="['md-ripple', rippleClasses]"
4-
@touchstart.passive.stop="touchStartCheck"
5-
@touchmove.passive.stop="touchMoveCheck"
6-
@mousedown.passive.stop="startRipple">
4+
@touchstart.passive="event => mdEventTrigger && touchStartCheck(event)"
5+
@touchmove.passive="event => mdEventTrigger && touchMoveCheck(event)"
6+
@mousedown.passive="event => mdEventTrigger && startRipple(event)">
77
<slot />
88
<md-wave v-for="ripple in ripples" :key="ripple.uuid" :class="['md-ripple-wave', waveClasses]" :style="ripple.waveStyles" @md-end="clearWave(ripple.uuid)" v-if="!isDisabled" />
99
</div>
@@ -23,7 +23,11 @@
2323
props: {
2424
mdActive: null,
2525
mdDisabled: Boolean,
26-
mdCentered: Boolean
26+
mdCentered: Boolean,
27+
mdEventTrigger: {
28+
type: Boolean,
29+
default: true
30+
}
2731
},
2832
data: () => ({
2933
ripples: [],

0 commit comments

Comments
 (0)