Skip to content

Commit f26334e

Browse files
pdanpdanrstoenescu
authored andcommitted
QBtn repeat, removeChild guard, show|hidePromise catch (quasarframework#2213)
* QBtn repeat, removeChild guard, show|hidePromise catch - QBtn: fix multiple clicks and not working repeat - Guard removeChild - QDialog, QActionSheet: remove duplicate cancel emit (it's done in dismiss) - Add catch for showPromise and hidePromise in model-toggle on cancel - QModal: remove from DOM when closed * Update scroll.js
1 parent 29c475a commit f26334e

File tree

13 files changed

+51
-25
lines changed

13 files changed

+51
-25
lines changed

dev/components/components/button.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<q-btn :key="`n_1_1_${ n }`" :type="tag" :size="n" dense icon="android" color="primary" />
88
<q-btn :key="`n_1_2_${ n }`" :type="tag" :size="n" icon="android" color="primary" />
99
<q-btn :key="`n_1_3_${ n }`" :type="tag" :size="n" label="Test" color="primary" />
10-
<q-btn :key="`n_1_4_${ n }`" :type="tag" :size="n" icon="android" color="primary" label="Test"/>
10+
<q-btn :key="`n_1_4_${ n }`" :type="tag" :size="n" icon="android" color="primary" label="Test" />
1111
<q-btn :key="`n_1_5_${ n }`" :type="tag" :size="n" round icon="android" color="primary" />
1212
<q-btn :key="`n_1_6_${ n }`" :type="tag" :size="n" round icon="android" color="primary" dense />
1313
<q-btn :key="`n_1_7_${ n }`" :type="tag" :size="n" label="Test" color="primary" />
@@ -17,7 +17,7 @@
1717
<template v-for="n in ['xs', 'sm', 'md', 'lg', 'xl']">
1818
<q-btn :key="`n_2_1_${ n }`" :type="tag" :size="n" dense label="Test" color="primary" />
1919
<q-btn :key="`n_2_2_${ n }`" :type="tag" :size="n" dense icon="android" color="primary" />
20-
<q-btn :key="`n_2_3_${ n }`" :type="tag" :size="n" dense icon="android" color="primary" label="Test"/>
20+
<q-btn :key="`n_2_3_${ n }`" :type="tag" :size="n" dense icon="android" color="primary" label="Test" />
2121
<q-btn :key="`n_2_4_${ n }`" :type="tag" :size="n" dense round icon="android" color="primary" />
2222
<span :key="`n_2_5_${ n }`">{{ n }}</span>
2323
<br :key="`n_2_6_${ n }`"><br :key="`n_2_7_${ n }`">
@@ -85,8 +85,8 @@
8585
</div>
8686

8787
<br><br>
88-
<q-btn :type="tag" color="amber" text-color="black" icon="map" label="Some label" />
89-
<q-btn :type="tag" text-color="amber" icon="map" label="Some label" />
88+
<q-btn :type="tag" color="amber" text-color="black" icon="map" label="Some label" @click="onClick" />
89+
<q-btn :type="tag" text-color="amber" icon="map" label="Some label" @click="onClick" />
9090

9191
<br><br>
9292
<div class="caption">Keep holding click</div>

dev/components/components/tooltip.vue

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040
<strong>Tooltip</strong> on <em>bottom</em> (<q-icon name="keyboard_arrow_down" />)
4141
</q-tooltip>
4242
</q-btn>
43+
<q-btn color="orange" label="With loading" :loading="loading" @click="setLoading">
44+
<q-tooltip anchor="bottom middle" self="top middle" :offset="[10, 10]">
45+
<strong>Tooltip</strong> on <em>bottom</em> (<q-icon name="keyboard_arrow_down" />)
46+
</q-tooltip>
47+
</q-btn>
4348
</div>
4449

4550
<q-card style="margin-top: 75px">
@@ -104,6 +109,7 @@ export default {
104109
data () {
105110
return {
106111
toggle: false,
112+
loading: false,
107113
anchorOrigin: {vertical: 'bottom', horizontal: 'middle'},
108114
selfOrigin: {vertical: 'top', horizontal: 'middle'}
109115
}
@@ -115,6 +121,14 @@ export default {
115121
self () {
116122
return `${this.selfOrigin.vertical} ${this.selfOrigin.horizontal}`
117123
}
124+
},
125+
methods: {
126+
setLoading () {
127+
this.loading = true
128+
setTimeout(() => {
129+
this.loading = false
130+
}, 1000)
131+
}
118132
}
119133
}
120134
</script>

dev/components/global/action-sheet.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
@show="onShow"
3434
@hide="onHide"
3535
@cancel="onCancel"
36+
@escape-key="onEscape"
3637
@ok="onOk"
3738
title="Action Sheet"
3839
:actions="[
@@ -110,6 +111,9 @@ export default {
110111
onCancel (data) {
111112
console.log('onCancel', data)
112113
},
114+
onEscape (data) {
115+
console.log('onEscape', data)
116+
},
113117
onHide (data) {
114118
console.log('onHide', data)
115119
},

dev/components/global/dialog.vue

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
ref="dialog"
77
stack-buttons
88
@cancel="onCancel"
9+
@escape-key="onEscape"
910
@ok="onOk"
1011
@show="onShow"
1112
@hide="onHide"
@@ -69,16 +70,19 @@ export default {
6970
this.showDialog = !this.showDialog
7071
},
7172
onOk () {
72-
console.log('ok')
73+
console.log('onOk')
7374
},
7475
onCancel () {
75-
console.log('cancel')
76+
console.log('onCancel')
77+
},
78+
onEscape () {
79+
console.log('onEscape')
7680
},
7781
onShow () {
78-
console.log('show')
82+
console.log('onShow')
7983
},
8084
onHide () {
81-
console.log('hide')
85+
console.log('onHide')
8286
},
8387
choose (okFn, hero) {
8488
if (this.name.length === 0) {

src/components/action-sheet/QActionSheet.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ export default {
9292
},
9393
'escape-key': () => {
9494
this.$emit('escape-key')
95-
this.$emit('cancel')
9695
}
9796
}
9897
}, child)

src/components/btn/QBtn.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,11 @@ export default {
8585
clearTimeout(this.timer)
8686
},
8787
__onKeyDown (e, repeat) {
88-
if (this.type || this.isDisabled || e.keyCode !== 13) {
88+
if (this.isDisabled || e.keyCode !== 13) {
8989
return
9090
}
9191
this.active = true
92-
if (repeat) {
93-
this.__startRepeat(e)
94-
}
92+
repeat ? this.__startRepeat(e) : stopAndPrevent(e)
9593
},
9694
__onKeyUp (e, repeat) {
9795
if (!this.active) {

src/components/dialog/QDialog.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ export default {
116116

117117
node = this.$refs.modal.$el.getElementsByClassName('q-btn')
118118
if (node.length) {
119-
console.log('found btn')
120119
node[node.length - 1].focus()
121120
}
122121
},
@@ -128,7 +127,6 @@ export default {
128127
},
129128
'escape-key': () => {
130129
this.$emit('escape-key')
131-
this.$emit('cancel')
132130
}
133131
}
134132
}, child)

src/components/modal/QModal.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,7 @@ export default {
204204
EscapeKey.pop()
205205
this.__preventScroll(false)
206206
this.__register(false)
207-
if (!this.noRefocus) {
208-
setTimeout(() => this.__refocusTarget && this.__refocusTarget.focus(), 300)
209-
}
207+
!this.noRefocus && this.__refocusTarget && this.__refocusTarget.focus()
210208
},
211209
__stopPropagation (e) {
212210
e.stopPropagation()
@@ -230,6 +228,10 @@ export default {
230228
}
231229
document.body.classList[state.action]('q-responsive-modal')
232230
}
231+
},
232+
__removeChild () {
233+
const parentNode = this.$el.parentNode
234+
parentNode && parentNode.removeChild(this.$el)
233235
}
234236
},
235237
mounted () {
@@ -238,9 +240,7 @@ export default {
238240
}
239241
},
240242
beforeDestroy () {
241-
if (this.$el.parentNode) {
242-
this.$el.parentNode.removeChild(this.$el)
243-
}
243+
this.__removeChild()
244244
},
245245
render (h) {
246246
return h('transition', {
@@ -251,9 +251,11 @@ export default {
251251
},
252252
enterCancelled: () => {
253253
this.showPromise && this.showPromiseReject()
254+
this.__removeChild()
254255
},
255256
afterLeave: () => {
256257
this.hidePromise && this.hidePromiseResolve()
258+
this.__removeChild()
257259
},
258260
leaveCancelled: () => {
259261
this.hidePromise && this.hidePromiseReject()

src/components/popover/QPopover.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ export default {
138138
window.removeEventListener('resize', this.__updatePosition, listenOpts.passive)
139139
EscapeKey.pop()
140140

141-
document.body.removeChild(this.$el)
141+
const parentNode = this.$el.parentNode
142+
parentNode && parentNode.removeChild(this.$el)
142143
this.hidePromise && this.hidePromiseResolve()
143144
if (!this.noRefocus && this.__refocusTarget) {
144145
this.__refocusTarget.focus()

src/components/tooltip/QTooltip.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ export default {
6868

6969
this.scrollTarget.removeEventListener('scroll', this.hide, listenOpts.passive)
7070
window.removeEventListener('resize', this.__debouncedUpdatePosition, listenOpts.passive)
71-
document.body.removeChild(this.$el)
71+
72+
const parentNode = this.$el.parentNode
73+
parentNode && parentNode.removeChild(this.$el)
7274
if (this.$q.platform.is.mobile) {
7375
document.body.removeEventListener('click', this.hide, true)
7476
}

0 commit comments

Comments
 (0)