Skip to content

Commit d52954a

Browse files
VdustRmarcosmoura
authored andcommitted
fix(MdRipple): clear immediately (#1506)
* fix(MdRipple): clear immediately * refactor(MdWave): rename wave end event * fix(MdRipple): check disable * fix(MdRipple): always reset active
1 parent 30c2f80 commit d52954a

File tree

3 files changed

+61
-30
lines changed

3 files changed

+61
-30
lines changed

src/components/MdRipple/MdRipple.vue

+14-30
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,23 @@
33
:class="['md-ripple', rippleClasses]"
44
@touchstart.passive.stop="touchStartCheck"
55
@touchmove.passive.stop="touchMoveCheck"
6-
@touchend.passive.stop="clearWave"
7-
@mousedown.passive.stop="startRipple"
8-
@mouseup.passive.stop="clearWave">
6+
@mousedown.passive.stop="startRipple">
97
<slot />
10-
11-
<transition-group name="md-ripple" v-if="!isDisabled">
12-
<span v-for="(ripple, index) in ripples" :key="'ripple'+index" :class="['md-ripple-wave', waveClasses]" :style="ripple.waveStyles" />
13-
</transition-group>
8+
<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" />
149
</div>
1510
</template>
1611

1712
<script>
1813
import raf from 'raf'
1914
import MdComponent from 'core/MdComponent'
20-
import debounce from 'core/utils/MdDebounce'
15+
import uuid from 'core/utils/MdUuid'
16+
import MdWave from './MdWave'
2117
2218
export default new MdComponent({
2319
name: 'MdRipple',
20+
components: {
21+
MdWave
22+
},
2423
props: {
2524
mdActive: null,
2625
mdDisabled: Boolean,
@@ -55,12 +54,11 @@
5554
this.startRipple({
5655
type: 'mousedown'
5756
})
58-
this.$emit('update:mdActive', false)
5957
} else if (isEvent) {
6058
this.startRipple(active)
61-
this.$emit('update:mdActive', false)
6259
}
63-
this.clearWave()
60+
61+
this.$emit('update:mdActive', false)
6462
}
6563
},
6664
methods: {
@@ -88,8 +86,8 @@
8886
8987
this.eventType = $event.type
9088
this.ripples.push({
91-
animating: true,
92-
waveStyles: this.applyStyles(position, size)
89+
waveStyles: this.applyStyles(position, size),
90+
uuid: uuid()
9391
})
9492
}
9593
})
@@ -103,9 +101,9 @@
103101
height: size
104102
}
105103
},
106-
clearWave: debounce(function () {
107-
this.ripples = []
108-
}, 2000),
104+
clearWave (uuid) {
105+
uuid ? this.ripples = this.ripples.filter(ripple => ripple.uuid !== uuid) : this.ripples = []
106+
},
109107
getSize () {
110108
const { offsetWidth, offsetHeight } = this.$el
111109
@@ -169,18 +167,4 @@
169167
z-index: 2;
170168
}
171169
}
172-
173-
.md-ripple-enter-active {
174-
transition: .8s $md-transition-stand-timing;
175-
transition-property: opacity, transform;
176-
will-change: opacity, transform;
177-
&.md-centered {
178-
transition-duration: 1.2s;
179-
}
180-
}
181-
182-
.md-ripple-enter {
183-
opacity: .26;
184-
transform: scale(.26) translateZ(0);
185-
}
186170
</style>

src/components/MdRipple/MdWave.vue

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<template>
2+
<transition name="md-ripple" @after-enter="end">
3+
<span v-if="animating" />
4+
</transition>
5+
</template>
6+
7+
<script>
8+
import MdComponent from 'core/MdComponent'
9+
export default new MdComponent({
10+
name: 'MdWave',
11+
data () {
12+
return {
13+
animating: true
14+
}
15+
},
16+
props: {
17+
waveClasses: null,
18+
waveStyles: null
19+
},
20+
methods: {
21+
end () {
22+
this.animating = null
23+
this.$emit('md-end')
24+
}
25+
}
26+
})
27+
</script>
28+
29+
<style lang="scss">
30+
@import "~components/MdAnimation/variables";
31+
32+
.md-ripple-enter-active {
33+
transition: .8s $md-transition-stand-timing;
34+
transition-property: opacity, transform;
35+
will-change: opacity, transform;
36+
&.md-centered {
37+
transition-duration: 1.2s;
38+
}
39+
}
40+
41+
.md-ripple-enter {
42+
opacity: .26;
43+
transform: scale(.26) translateZ(0);
44+
}
45+
</style>

src/components/MdRipple/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import material from 'vue-material/material'
22
import MdRipple from './MdRipple'
3+
import MdWave from './MdWave'
34

45
export default Vue => {
56
material(Vue)
67
Vue.component(MdRipple.name, MdRipple)
8+
Vue.component(MdWave.name, MdWave)
79
}

0 commit comments

Comments
 (0)