Skip to content

Commit 06ef948

Browse files
committed
refactor: Model toggle updates
1 parent 7dd06df commit 06ef948

File tree

4 files changed

+121
-104
lines changed

4 files changed

+121
-104
lines changed

dev/components/global/dialog.vue

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ export default {
4343
this.showDialog = !this.showDialog
4444
},
4545
onOk (data) {
46-
console.log('onOK', data)
46+
console.log('>>> onOK', data)
4747
},
4848
onCancel (data) {
49-
console.log('onCancel', data)
49+
console.log('>>> onCancel', data)
5050
},
5151
onHide (data) {
52-
console.log('onHide', data)
52+
console.log('>>> onHide', data)
5353
},
5454
onShow (data) {
55-
console.log('onShow', data)
55+
console.log('>>> onShow', data)
5656
},
5757
adHoc () {
5858
this.$q.dialog({
@@ -66,9 +66,9 @@ export default {
6666
// preventClose: true,
6767
color: 'secondary'
6868
}).then(data => {
69-
console.log('OK, received:', data)
69+
console.log('>>>> OK, received:', data)
7070
}).catch(() => {
71-
console.log('dismissed')
71+
console.log('>>>> Cancel')
7272
})
7373
},
7474
adHoc2 () {
@@ -89,9 +89,9 @@ export default {
8989
preventClose: true,
9090
color: 'secondary'
9191
}).then(data => {
92-
console.log('OK, received:', data)
92+
console.log('>>>> OK, received:', data)
9393
}).catch(() => {
94-
console.log('dismissed')
94+
console.log('>>>> Cancel')
9595
})
9696
},
9797
adHoc3 () {
@@ -101,9 +101,9 @@ export default {
101101
cancel: true,
102102
preventClose: true
103103
}).then(() => {
104-
console.log('OK')
104+
console.log('>>> OK')
105105
}).catch(() => {
106-
console.log('Cancel')
106+
console.log('>>> Cancel')
107107
})
108108
}
109109
}

src/components/dialog/QDialog.js

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ export default {
2525
default: 'primary'
2626
}
2727
},
28-
watch: {
29-
value (val) {
30-
this[val ? 'show' : 'hide']()
31-
}
32-
},
3328
render (h) {
3429
const
3530
child = [],
@@ -90,19 +85,38 @@ export default {
9085
return h(QModal, {
9186
ref: 'modal',
9287
props: {
88+
value: this.value,
9389
minimized: true,
9490
noBackdropDismiss: this.preventClose,
9591
noEscDismiss: this.preventClose,
9692
position: this.position
9793
},
9894
on: {
95+
input: val => {
96+
this.$emit('input', val)
97+
},
9998
show: () => {
99+
console.log('DIALOG show emitting show')
100100
this.$emit('show')
101-
this.$emit('input', true)
101+
102+
if (!this.$q.platform.is.desktop) {
103+
return
104+
}
105+
106+
let node = this.$refs.modal.$el.getElementsByTagName('INPUT')
107+
if (node.length) {
108+
node[0].focus()
109+
return
110+
}
111+
112+
node = this.$refs.modal.$el.getElementsByTagName('INPUT')
113+
if (node.length) {
114+
node[node.length - 1].focus()
115+
}
102116
},
103117
hide: () => {
118+
console.log('DIALOG hide emitting hide')
104119
this.$emit('hide')
105-
this.$emit('input', false)
106120
},
107121
dismiss: () => {
108122
console.log('DIALOG received dismiss, hiding then emitting cancel')
@@ -135,24 +149,7 @@ export default {
135149
methods: {
136150
show () {
137151
console.log('DIALOG show')
138-
return this.$refs.modal.show().then(() => {
139-
console.log('DIALOG show emitting show')
140-
141-
if (!this.$q.platform.is.desktop) {
142-
return
143-
}
144-
145-
let node = this.$refs.modal.$el.getElementsByTagName('INPUT')
146-
if (node.length) {
147-
node[0].focus()
148-
return
149-
}
150-
151-
node = this.$refs.modal.$el.getElementsByTagName('INPUT')
152-
if (node.length) {
153-
node[node.length - 1].focus()
154-
}
155-
})
152+
return this.$refs.modal.show()
156153
},
157154
hide () {
158155
let data
@@ -163,7 +160,7 @@ export default {
163160
console.log('DIALOG hide')
164161

165162
return this.$refs.modal.hide().then(() => {
166-
console.log('DIALOG hide', data)
163+
console.log('DIALOG hide data:', data)
167164
return data
168165
})
169166
},

src/components/modal/QModal.js

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ let openedModalNumber = 0
4949
export default {
5050
name: 'q-modal',
5151
mixins: [ModelToggleMixin],
52+
modelToggle: {
53+
history: true,
54+
showOnMount: true
55+
},
5256
props: {
5357
position: {
5458
type: String,
@@ -133,7 +137,7 @@ export default {
133137
})
134138
},
135139
__show () {
136-
console.log('MODAL show')
140+
console.log('MODAL __show')
137141
const body = document.body
138142

139143
body.appendChild(this.$el)
@@ -147,21 +151,18 @@ export default {
147151
}
148152
})
149153

150-
this.$once('show', () => {
151-
console.log('trigger')
152-
let content = this.$refs.content
153-
content.scrollTop = 0
154-
;['modal-scroll', 'layout-view'].forEach(c => {
155-
[].slice.call(content.getElementsByClassName(c)).forEach(el => {
156-
el.scrollTop = 0
157-
})
154+
openedModalNumber++
155+
156+
let content = this.$refs.content
157+
content.scrollTop = 0
158+
;['modal-scroll', 'layout-view'].forEach(c => {
159+
[].slice.call(content.getElementsByClassName(c)).forEach(el => {
160+
el.scrollTop = 0
158161
})
159162
})
160-
161-
openedModalNumber++
162163
},
163164
__hide () {
164-
console.log('MODAL hide')
165+
console.log('MODAL __hide')
165166
EscapeKey.pop()
166167
openedModalNumber--
167168

@@ -173,11 +174,6 @@ export default {
173174
}
174175
}
175176
},
176-
mounted () {
177-
if (this.value) {
178-
this.show()
179-
}
180-
},
181177
beforeDestroy () {
182178
if (this.$el.parentNode) {
183179
this.$el.parentNode.removeChild(this.$el)
@@ -192,19 +188,19 @@ export default {
192188
},
193189
on: {
194190
afterEnter: () => {
195-
console.log('show resolve')
191+
console.log('MODAL show resolve')
196192
this.showPromise && this.showPromiseResolve()
197193
},
198194
enterCancelled: () => {
199-
console.log('show cancel')
195+
console.log('MODAL show cancel')
200196
this.showPromise && this.showPromiseReject()
201197
},
202198
afterLeave: () => {
203-
console.log('hide resolve')
199+
console.log('MODAL hide resolve')
204200
this.hidePromise && this.hidePromiseResolve()
205201
},
206202
leaveCancelled: () => {
207-
console.log('hide reject')
203+
console.log('MODAL hide reject')
208204
this.hidePromise && this.hidePromiseReject()
209205
}
210206
}

0 commit comments

Comments
 (0)