Skip to content

Commit c4f55a9

Browse files
committed
feat: Add v-close-overlay directive
1 parent 5c62cd8 commit c4f55a9

File tree

7 files changed

+127
-5
lines changed

7 files changed

+127
-5
lines changed

dev/components/components/context-menu.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@
3535
>
3636
Target area
3737

38-
<q-context-menu ref="context">
38+
<q-context-menu>
3939
<q-list link separator no-border style="min-width: 150px; max-height: 300px;">
4040
<q-item
4141
v-for="n in 10"
4242
:key="n"
43-
@click="showNotify(), $refs.context.hide()"
43+
v-close-overlay
44+
@click.native="showNotify()"
4445
>
4546
<q-item-main label="Label" sublabel="Value" />
4647
</q-item>

dev/components/components/popover.vue

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,30 @@
1515
<q-item
1616
v-for="n in 20"
1717
:key="n"
18-
@click.native="showNotify(), $refs.popover1.hide()"
18+
v-close-overlay
19+
@click.native="showNotify()"
1920
>
2021
<q-item-main label="Label" sublabel="Click me" />
2122
</q-item>
2223
</q-list>
2324
</q-popover>
2425
</q-btn>
2526

27+
<q-btn color="primary" icon="map">
28+
<q-popover>
29+
<q-list link separator class="scroll" style="min-width: 100px">
30+
<q-item
31+
v-for="n in 20"
32+
:key="n"
33+
v-close-overlay
34+
@click.native="showNotify()"
35+
>
36+
<q-item-main label="X Label" sublabel="X Click me" />
37+
</q-item>
38+
</q-list>
39+
</q-popover>
40+
</q-btn>
41+
2642
<q-btn ref="target4" color="negative" label="Disabled Popover">
2743
<q-popover disable>
2844
This Popover content won't be shown because of "disable"
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<template>
2+
<div class="layout-padding">
3+
<!--
4+
This is for fast tests.
5+
Use this page but don't add it into your commits (leave it outside
6+
of your commit).
7+
8+
For some test that you think it should be persistent,
9+
make a new *.vue file here or in another folder under /dev/components.
10+
-->
11+
<q-btn color="primary" icon="map">
12+
<q-popover>
13+
<q-list link separator class="scroll" style="min-width: 100px">
14+
<!--<q-item
15+
v-close-overlay
16+
@click.native="showNotify"
17+
>
18+
<q-item-main label="Closable" sublabel="Closes" />
19+
</q-item>-->
20+
<q-btn color="primary" v-close-overlay label="Shut up" icon="map" />
21+
<q-item
22+
@click.native="showNotify"
23+
>
24+
<q-item-main label="Does nothing" sublabel="sublabel" />
25+
</q-item>
26+
</q-list>
27+
</q-popover>
28+
</q-btn>
29+
30+
<q-btn color="primary" icon="map" :label="popover ? 'yes' : 'no'">
31+
<q-popover v-model="popover">
32+
<q-list link separator class="scroll" style="min-width: 100px">
33+
<q-btn color="primary" v-close-overlay label="X Shut up" icon="map" @click.native="showNotify" />
34+
<q-item @click.native="showNotify">
35+
<q-item-main label="X Does nothing" sublabel="sublabel" />
36+
</q-item>
37+
</q-list>
38+
</q-popover>
39+
</q-btn>
40+
41+
42+
43+
44+
</div>
45+
</template>
46+
47+
<script>
48+
export default {
49+
data () {
50+
return {
51+
popover: false
52+
}
53+
},
54+
methods: {
55+
showNotify () {
56+
console.log('@click')
57+
}
58+
}
59+
}
60+
</script>

src/components/knob/QKnob.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export default {
175175
this.min,
176176
this.max
177177
)
178-
178+
179179
if (this.computedDecimals) {
180180
value = parseFloat(value.toFixed(this.computedDecimals))
181181
}

src/components/popover/QPopover.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export default {
117117

118118
this.hide(evt)
119119
},
120-
__hide (evt) {
120+
__hide () {
121121
clearTimeout(this.timer)
122122

123123
document.body.removeEventListener('click', this.__bodyHide, true)

src/directives.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import BackToTop from './directives/back-to-top'
2+
import CloseOverlay from './directives/close-overlay'
23
import GoBack from './directives/go-back'
34
import Move from './directives/move'
45
import Ripple from './directives/ripple'
@@ -10,6 +11,7 @@ import TouchSwipe from './directives/touch-swipe'
1011

1112
export {
1213
BackToTop,
14+
CloseOverlay,
1315
GoBack,
1416
Move,
1517
Ripple,

src/directives/close-overlay.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
/* function updateBinding (el, { value, modifiers }) {
3+
const ctx = el.__qclose
4+
} */
5+
6+
/* ,
7+
update (el, binding) {
8+
if (binding.oldValue !== binding.value) {
9+
updateBinding(el, binding)
10+
}
11+
} */
12+
13+
export default {
14+
name: 'close-overlay',
15+
bind (el, binding, vnode) {
16+
console.log('bind')
17+
18+
let vm = vnode.componentInstance
19+
while ((vm = vm.$parent)) {
20+
const name = vm.$options.name
21+
if (name === 'q-popover' || name === 'q-modal') {
22+
break
23+
}
24+
}
25+
26+
el.__qclose = {
27+
handler () {
28+
vm && vm.hide()
29+
}
30+
}
31+
},
32+
inserted (el) {
33+
console.log('inserted')
34+
let ctx = el.__qclose
35+
el.addEventListener('click', ctx.handler)
36+
},
37+
unbind (el) {
38+
console.log('unbind')
39+
let ctx = el.__qclose
40+
el.removeEventListener('click', ctx.handler)
41+
delete el.__qclose
42+
}
43+
}

0 commit comments

Comments
 (0)