Skip to content

Commit d547796

Browse files
committed
feat(Ripple): "early" modifier (or Boolean prop when using Object form) quasarframework#6524
1 parent ff1c824 commit d547796

File tree

5 files changed

+72
-25
lines changed

5 files changed

+72
-25
lines changed

ui/dev/src/pages/components/tabs.vue

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
</q-tabs>
1414

1515
<q-tabs :dense="dense" vertical inline-label class="vertical-tabs" v-model="vtab" style="margin-right: 25px;">
16-
<q-tab name="one" label="wifi" icon="wifi" />
17-
<q-tab name="two" label="bluetooth" icon="bluetooth" />
18-
<q-tab name="three" label="map" icon="map" />
19-
<q-tab name="four" label="phone" icon="phone" />
20-
<q-tab name="five" label="location" icon="location_on" />
21-
<q-tab name="six" label="favorite" icon="favorite" />
22-
<q-tab name="seven" label="home" icon="home" />
23-
<q-tab name="eight" label="info" icon="info" />
16+
<q-tab :ripple="{ early: true }" name="one" label="wifi" icon="wifi" />
17+
<q-tab :ripple="{ early: true }" name="two" label="bluetooth" icon="bluetooth" />
18+
<q-tab :ripple="{ early: true }" name="three" label="map" icon="map" />
19+
<q-tab :ripple="{ early: true }" name="four" label="phone" icon="phone" />
20+
<q-tab :ripple="{ early: true }" name="five" label="location" icon="location_on" />
21+
<q-tab :ripple="{ early: true }" name="six" label="favorite" icon="favorite" />
22+
<q-tab :ripple="{ early: true }" name="seven" label="home" icon="home" />
23+
<q-tab :ripple="{ early: true }" name="eight" label="info" icon="info" />
2424
</q-tabs>
2525

2626
<q-tabs :dense="dense" vertical class="vertical-tabs" v-model="vtab" style="margin-right: 25px;">
File renamed without changes.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<template>
2+
<div class="q-layout-padding">
3+
<div class="q-gutter-sm">
4+
<q-btn label="Regular" @click="onClick" />
5+
<q-btn label="Regular" loading @click="onClick" />
6+
<q-btn label="Link" type="a" href="about:blank" target="_blank" @click="onClick" />
7+
</div>
8+
9+
<div class="q-gutter-sm q-pt-md">
10+
<q-btn label="Regular early" :ripple="{ early: true }" @click="onClick" />
11+
<q-btn label="Regular early" loading :ripple="{ early: true }" @click="onClick" />
12+
<q-btn label="Link early" :ripple="{ early: true }" type="a" href="about:blank" target="_blank" @click="onClick" />
13+
</div>
14+
</div>
15+
</template>
16+
17+
<script>
18+
export default {
19+
methods: {
20+
onClick () {
21+
console.log('onClick')
22+
}
23+
}
24+
}
25+
</script>

ui/src/components/btn/QBtn.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export default Vue.extend({
3838
return this.ripple === false
3939
? false
4040
: Object.assign(
41-
{ keyCodes: [] },
41+
{ keyCodes: this.isLink === true ? [ 13, 32 ] : [ 13 ] },
4242
this.ripple === true ? {} : this.ripple
4343
)
4444
},
@@ -48,6 +48,16 @@ export default Vue.extend({
4848
if (val > 0) {
4949
return { transition: 'transform 0.6s', transform: `translateX(${val - 100}%)` }
5050
}
51+
},
52+
53+
onLoadingEvents () {
54+
return {
55+
mousedown: this.__onLoadingEvt,
56+
touchstart: this.__onLoadingEvt,
57+
click: this.__onLoadingEvt,
58+
keydown: this.__onLoadingEvt,
59+
keyup: this.__onLoadingEvt
60+
}
5161
}
5262
},
5363

@@ -290,10 +300,7 @@ export default Vue.extend({
290300

291301
if (this.loading === true) {
292302
// stop propagation and ripple
293-
data.on = {
294-
click: this.__onLoadingEvt,
295-
keyup: this.__onLoadingEvt
296-
}
303+
data.on = this.onLoadingEvents
297304

298305
this.percentage !== void 0 && child.push(
299306
h('div', {

ui/src/directives/Ripple.js

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { css } from '../utils/dom.js'
2-
import { position, stop, listenOpts } from '../utils/event.js'
2+
import { position, stop } from '../utils/event.js'
3+
import { addEvt, cleanEvt } from '../utils/touch.js'
34
import { isKeyCode } from '../utils/key-composition.js'
45
import { client } from '../plugins/Platform.js'
6+
import throttle from '../utils/throttle.js'
57

68
function showRipple (evt, el, ctx, forceCenter) {
79
ctx.modifiers.stop === true && stop(evt)
@@ -64,16 +66,18 @@ function updateCtx (ctx, { value, modifiers, arg }) {
6466
if (ctx.enabled === true) {
6567
ctx.modifiers = Object(value) === value
6668
? {
69+
early: value.early === true || modifiers.early === true,
6770
stop: value.stop === true || modifiers.stop === true,
6871
center: value.center === true || modifiers.center === true,
6972
color: value.color || arg,
7073
keyCodes: [].concat(value.keyCodes || 13)
7174
}
7275
: {
76+
early: modifiers.early,
7377
stop: modifiers.stop,
7478
center: modifiers.center,
7579
color: arg,
76-
keyCodes: [13]
80+
keyCodes: [ 13 ]
7781
}
7882
}
7983
}
@@ -86,26 +90,32 @@ export default {
8690
modifiers: {},
8791
abort: [],
8892

89-
click (evt) {
90-
// on ENTER in form IE emits a PointerEvent with negative client cordinates
93+
start (evt) {
9194
if (
9295
ctx.enabled === true &&
9396
evt.qSkipRipple !== true &&
94-
(client.is.ie !== true || evt.clientX >= 0)
97+
// on ENTER in form IE emits a PointerEvent with negative client cordinates
98+
(client.is.ie !== true || evt.clientX >= 0) &&
99+
(
100+
ctx.modifiers.early === true
101+
? ['mousedown', 'touchstart'].includes(evt.type) === true
102+
: evt.type === 'click'
103+
)
95104
) {
96105
showRipple(evt, el, ctx, evt.qKeyEvent === true)
97106
}
98107
},
99108

100-
keyup (evt) {
109+
keystart: throttle(evt => {
101110
if (
102111
ctx.enabled === true &&
103112
evt.qSkipRipple !== true &&
104-
isKeyCode(evt, ctx.modifiers.keyCodes) === true
113+
isKeyCode(evt, ctx.modifiers.keyCodes) === true &&
114+
evt.type === `key${ctx.modifiers.early === true ? 'down' : 'up'}`
105115
) {
106116
showRipple(evt, el, ctx, true)
107117
}
108-
}
118+
}, 300)
109119
}
110120

111121
updateCtx(ctx, binding)
@@ -115,8 +125,14 @@ export default {
115125
}
116126

117127
el.__qripple = ctx
118-
el.addEventListener('click', ctx.click, listenOpts.passive)
119-
el.addEventListener('keyup', ctx.keyup, listenOpts.passive)
128+
129+
addEvt(ctx, 'main', [
130+
[ el, 'mousedown', 'start', 'passive' ],
131+
[ el, 'touchstart', 'start', 'passive' ],
132+
[ el, 'click', 'start', 'passive' ],
133+
[ el, 'keydown', 'keystart', 'passive' ],
134+
[ el, 'keyup', 'keystart', 'passive' ]
135+
])
120136
},
121137

122138
update (el, binding) {
@@ -127,8 +143,7 @@ export default {
127143
const ctx = el.__qripple_old || el.__qripple
128144
if (ctx !== void 0) {
129145
ctx.abort.forEach(fn => { fn() })
130-
el.removeEventListener('click', ctx.click, listenOpts.passive)
131-
el.removeEventListener('keyup', ctx.keyup, listenOpts.passive)
146+
cleanEvt(ctx, 'main')
132147
delete el[el.__qripple_old ? '__qripple_old' : '__qripple']
133148
}
134149
}

0 commit comments

Comments
 (0)