Skip to content

Commit 0372dac

Browse files
committed
fix(model-toggle): nextTick in model show()/hide()
1 parent 563ae96 commit 0372dac

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

ui/src/components/dialog/QDialog.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ export default Vue.extend({
188188
if (this.noFocus !== true) {
189189
document.activeElement.blur()
190190

191-
this.$nextTick(() => {
191+
this.__nextModelTick(() => {
192192
this.focus()
193193
})
194194
}

ui/src/components/menu/QMenu.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export default Vue.extend({
138138
document.activeElement.blur()
139139
}
140140

141-
this.$nextTick(() => {
141+
this.__nextModelTick(() => {
142142
this.updatePosition()
143143
this.noFocus !== true && this.focus()
144144
})

ui/src/components/tooltip/QTooltip.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export default Vue.extend({
7676

7777
this.__showPortal()
7878

79-
this.$nextTick(() => {
79+
this.__nextModelTick(() => {
8080
this.updatePosition()
8181
this.__configureScrollTarget()
8282
})

ui/src/mixins/model-toggle.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ export default {
5353
this.$emit('before-show', evt)
5454

5555
if (this.__show !== void 0) {
56+
this.__clearModelTick()
5657
this.__show(evt)
58+
this.__prepareModelTick()
5759
}
5860
else {
5961
this.$emit('show', evt)
@@ -87,7 +89,9 @@ export default {
8789
this.$emit('before-hide', evt)
8890

8991
if (this.__hide !== void 0) {
92+
this.__clearModelTick()
9093
this.__hide(evt)
94+
this.__prepareModelTick()
9195
}
9296
else {
9397
this.$emit('hide', evt)
@@ -101,6 +105,30 @@ export default {
101105
else if (val !== this.showing) {
102106
this[`__process${val === true ? 'Show' : 'Hide'}`](this.payload)
103107
}
108+
},
109+
110+
__nextModelTick (fn) {
111+
this.nextModelTick = fn
112+
},
113+
114+
__prepareModelTick () {
115+
if (this.nextModelTick !== void 0) {
116+
const fn = this.nextModelTick
117+
this.$nextTick(() => {
118+
if (this.nextModelTick === fn) {
119+
this.nextModelTick()
120+
this.nextModelTick = void 0
121+
}
122+
})
123+
}
124+
},
125+
126+
__clearModelTick () {
127+
this.nextModelTick = void 0
104128
}
129+
},
130+
131+
beforeDestroy () {
132+
this.nextModelTick = void 0
105133
}
106134
}

0 commit comments

Comments
 (0)