Skip to content

Commit bb4d595

Browse files
committed
fix: Opening Model / Drawer causes layout change quasarframework#1771
1 parent 21dd65f commit bb4d595

File tree

10 files changed

+131
-72
lines changed

10 files changed

+131
-72
lines changed

dev/components/components/modal.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@
110110
<h4>Modal</h4><p>This one gets displayed from {{position}}.</p>
111111
<q-btn color="orange" @click="$refs.positionModal.hide()">Close Me</q-btn>
112112
</q-modal>
113+
114+
<div style="height: 800px">&nbsp;</div>
113115
</div>
114116
</template>
115117

dev/components/new-layout/new-layout.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@
203203
</div>
204204
</div>
205205
</div>
206-
<q-modal v-model="toggle" :content-css="{padding: '50px', minWidth: '50vw'}">
206+
<q-modal minimized v-model="toggle" :content-css="{padding: '50px', minWidth: '50vw'}">
207207
<h4>Basic Modal</h4>
208208
<p v-for="n in 25" :key="`basic-${n}`">Scroll down to close</p>
209209
<q-btn color="primary" @click="toggle = false">Close</q-btn>

src/components/layout/QLayoutDrawer.js

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { css, cssTransform } from '../../utils/dom'
33
import { between } from '../../utils/format'
44
import { QResizeObservable } from '../observables'
55
import ModelToggleMixin from '../../mixins/model-toggle'
6+
import { stopAndPrevent, getMouseWheelDistance, wheelEvent } from '../../utils/event'
67

78
const
8-
bodyClassBelow = 'with-layout-drawer-opened',
9-
bodyClassAbove = 'with-layout-drawer-opened-above',
9+
bodyClass = 'q-drawer-scroll',
1010
duration = 150
1111

1212
export default {
@@ -216,6 +216,11 @@ export default {
216216
},
217217
stateDirection () {
218218
return (this.$q.i18n.rtl ? -1 : 1) * (this.rightSide ? 1 : -1)
219+
},
220+
containerOn () {
221+
if (this.$q.platform.is.desktop) {
222+
return { [wheelEvent.name]: this.__onWheel }
223+
}
219224
}
220225
},
221226
render (h) {
@@ -245,7 +250,10 @@ export default {
245250
}))
246251
}
247252

248-
return h('div', { staticClass: 'q-drawer-container' }, child.concat([
253+
return h('div', {
254+
staticClass: 'q-drawer-container',
255+
on: this.containerOn
256+
}, child.concat([
249257
h('aside', {
250258
ref: 'content',
251259
staticClass: `q-layout-drawer q-layout-transition q-layout-drawer-${this.side} scroll`,
@@ -307,6 +315,12 @@ export default {
307315
applyBackdrop (x) {
308316
this.$refs.backdrop && css(this.$refs.backdrop, { backgroundColor: `rgba(0,0,0,${x * 0.4})` })
309317
},
318+
__onWheel (e) {
319+
if (this.fixed) {
320+
stopAndPrevent(e)
321+
this.$refs.content.scrollTop += getMouseWheelDistance(e).pixelY
322+
}
323+
},
310324
__openByTouch (evt) {
311325
if (!this.belowBreakpoint) {
312326
return
@@ -330,7 +344,6 @@ export default {
330344
this.applyBackdrop(0)
331345
this.applyPosition(this.stateDirection * width)
332346
el.classList.remove('q-layout-drawer-delimiter')
333-
document.body.classList.remove(bodyClassBelow)
334347
}
335348
})
336349
return
@@ -347,7 +360,6 @@ export default {
347360

348361
if (evt.isFirst) {
349362
const el = this.$refs.content
350-
document.body.classList.add(bodyClassBelow)
351363
el.classList.add('no-transition')
352364
el.classList.add('q-layout-drawer-delimiter')
353365
}
@@ -389,6 +401,7 @@ export default {
389401
},
390402
__show () {
391403
this.layout.__animate()
404+
this.applyPosition(0)
392405

393406
if (this.belowBreakpoint) {
394407
const otherSide = this.layout.instances[this.rightSide ? 'left' : 'right']
@@ -398,15 +411,15 @@ export default {
398411
this.mobileOpened = true
399412
this.applyBackdrop(1)
400413
}
401-
402-
this.applyPosition(0)
403-
document.body.classList.add(this.belowBreakpoint ? bodyClassBelow : bodyClassAbove)
414+
else {
415+
document.body.classList.add(bodyClass)
416+
}
404417

405418
clearTimeout(this.timer)
406419
this.timer = setTimeout(() => {
407420
if (this.showPromise) {
408421
this.showPromise.then(() => {
409-
document.body.classList.remove(bodyClassAbove)
422+
document.body.classList.remove(bodyClass)
410423
})
411424
this.showPromiseResolve()
412425
}
@@ -420,8 +433,7 @@ export default {
420433
this.applyPosition((this.$q.i18n.rtl ? -1 : 1) * (this.rightSide ? 1 : -1) * this.size)
421434
this.applyBackdrop(0)
422435

423-
document.body.classList.remove(bodyClassAbove)
424-
document.body.classList.remove(bodyClassBelow)
436+
document.body.classList.remove(bodyClass)
425437

426438
this.timer = setTimeout(() => {
427439
this.hidePromise && this.hidePromiseResolve()

src/components/layout/layout.ios.styl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,16 @@ body
5959
&.q-layout-animate .q-layout-transition
6060
transition $layout-transition
6161

62-
&.with-layout-drawer-opened
63-
overflow hidden
64-
&.with-layout-drawer-opened-above
65-
overflow-x hidden
66-
6762
&.cordova.platform-ios
6863
.q-layout-header > .q-toolbar:first-child,
6964
.q-layout-header > .q-tabs:first-child .q-tabs-head
7065
.q-layout-drawer.top-padding
7166
padding-top $ios-statusbar-height
7267
min-height ($toolbar-min-height + $ios-statusbar-height)
7368

69+
.q-drawer-scroll
70+
overflow-x hidden
71+
7472
.layout-padding
7573
@media (max-width $breakpoint-sm-max)
7674
padding 1.5rem .5rem

src/components/layout/layout.mat.styl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,16 @@ body
5757
&.q-layout-animate .q-layout-transition
5858
transition $layout-transition
5959

60-
&.with-layout-drawer-opened
61-
overflow hidden
62-
&.with-layout-drawer-opened-above
63-
overflow-x hidden
64-
6560
&.cordova.platform-ios
6661
.q-layout-header > .q-toolbar:first-child,
6762
.q-layout-header > .q-tabs:first-child .q-tabs-head
6863
.q-layout-drawer.top-padding
6964
padding-top $ios-statusbar-height
7065
min-height ($toolbar-min-height + $ios-statusbar-height)
7166

67+
.q-drawer-scroll
68+
overflow-x hidden
69+
7270
.layout-padding
7371
@media (max-width $breakpoint-sm-max)
7472
padding 1.5rem .5rem

src/components/modal/QModal.js

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import EscapeKey from '../../utils/escape-key'
22
import extend from '../../utils/extend'
33
import ModelToggleMixin from '../../mixins/model-toggle'
4+
import { stopAndPrevent, getMouseWheelDistance, wheelEvent } from '../../utils/event'
45

56
const positions = {
67
top: 'items-start justify-center with-backdrop',
@@ -43,7 +44,10 @@ function additionalCSS (position) {
4344
return css
4445
}
4546

46-
let openedModalNumber = 0
47+
let modals = {
48+
responsive: 0,
49+
maximized: 0
50+
}
4751

4852
export default {
4953
name: 'QModal',
@@ -130,6 +134,19 @@ export default {
130134
}
131135

132136
return this.contentCss
137+
},
138+
contentOn () {
139+
const evt = {
140+
click: this.__stopPropagation,
141+
touchstart: this.__stopPropagation
142+
}
143+
if (this.$q.platform.is.desktop) {
144+
evt[wheelEvent.name] = e => {
145+
stopAndPrevent(e)
146+
this.$refs.content.scrollTop += getMouseWheelDistance(e).pixelY
147+
}
148+
}
149+
return evt
133150
}
134151
},
135152
methods: {
@@ -145,9 +162,7 @@ export default {
145162
const body = document.body
146163

147164
body.appendChild(this.$el)
148-
if (openedModalNumber === 0) {
149-
body.classList.add('with-modal')
150-
}
165+
this.__register(true)
151166

152167
EscapeKey.register(() => {
153168
if (!this.noEscDismiss) {
@@ -157,8 +172,6 @@ export default {
157172
}
158173
})
159174

160-
openedModalNumber++
161-
162175
let content = this.$refs.content
163176
if (this.$q.platform.is.ios) {
164177
// workaround the iOS hover/touch issue
@@ -173,10 +186,29 @@ export default {
173186
},
174187
__hide () {
175188
EscapeKey.pop()
176-
openedModalNumber--
189+
this.__register(false)
190+
},
191+
__stopPropagation (e) {
192+
e.stopPropagation()
193+
},
194+
__register (opening) {
195+
let state = opening
196+
? { action: 'add', step: 1 }
197+
: { action: 'remove', step: -1 }
177198

178-
if (openedModalNumber === 0) {
179-
document.body.classList.remove('with-modal')
199+
if (this.maximized) {
200+
modals.maximized += state.step
201+
if (!opening && modals.maximized > 0) {
202+
return
203+
}
204+
document.body.classList[state.action]('q-maximized-modal')
205+
}
206+
else if (!this.minimized) {
207+
modals.responsive += state.step
208+
if (!opening && modals.responsive > 0) {
209+
return
210+
}
211+
document.body.classList[state.action]('q-responsive-modal')
180212
}
181213
}
182214
},
@@ -212,7 +244,8 @@ export default {
212244
staticClass: 'modal fullscreen row',
213245
'class': this.modalClasses,
214246
on: {
215-
click: this.__dismiss
247+
click: this.__dismiss,
248+
[wheelEvent.name]: stopAndPrevent
216249
},
217250
directives: [{
218251
name: 'show',
@@ -224,14 +257,7 @@ export default {
224257
staticClass: 'modal-content scroll',
225258
style: this.modalCss,
226259
'class': this.contentClasses,
227-
on: {
228-
click (e) {
229-
e.stopPropagation()
230-
},
231-
touchstart (e) {
232-
e.stopPropagation()
233-
}
234-
}
260+
on: this.contentOn
235261
}, [ this.$slots.default ])
236262
])
237263
])

src/components/modal/modal.ios.styl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
body.with-modal
2-
overflow hidden !important
3-
41
minimized-modal()
52
max-width 80vw
63
max-height 80vh
@@ -47,6 +44,8 @@ maximized-modal()
4744
transform translateX(30%)
4845

4946
@media (max-width $breakpoint-sm-max)
47+
.q-responsive-modal
48+
overflow hidden
5049
.modal:not(.minimized)
5150
.modal-content
5251
maximized-modal()
@@ -59,6 +58,9 @@ maximized-modal()
5958
&.q-modal-leave-active .modal-content
6059
transform scale(.8)
6160

61+
.q-maximized-modal
62+
overflow hidden
63+
6264
.modal, .modal-content
6365
transition all .2s ease-in-out
6466

src/components/modal/modal.mat.styl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
body.with-modal
2-
overflow hidden !important
3-
41
minimized-modal()
52
max-width 80vw
63
max-height 80vh
@@ -45,6 +42,8 @@ maximized-modal()
4542
transform translateY(30%)
4643

4744
@media (max-width $breakpoint-sm-max)
45+
.q-responsive-modal
46+
overflow hidden
4847
.modal:not(.minimized)
4948
.modal-content
5049
maximized-modal()
@@ -57,6 +56,9 @@ maximized-modal()
5756
&.q-modal-leave-active .modal-content
5857
transform scale(.8)
5958

59+
.q-maximized-modal
60+
overflow hidden
61+
6062
.modal, .modal-content
6163
transition all .2s ease-in-out
6264

src/components/scroll-area/QScrollArea.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import extend from '../../utils/extend'
22
import { between } from '../../utils/format'
3-
import { getMouseWheelDistance } from '../../utils/event'
3+
import { stopAndPrevent, getMouseWheelDistance, wheelEvent } from '../../utils/event'
44
import { setScrollPosition } from '../../utils/scroll'
55
import { QResizeObservable, QScrollObservable } from '../observables'
66
import TouchPan from '../../directives/touch-pan'
@@ -122,7 +122,7 @@ export default {
122122
const el = this.$refs.target
123123
el.scrollTop += getMouseWheelDistance(e).pixelY
124124
if (el.scrollTop > 0 && el.scrollTop + this.containerHeight < this.scrollHeight) {
125-
e.preventDefault()
125+
stopAndPrevent(e)
126126
}
127127
},
128128
__setActive (active, timer) {
@@ -173,9 +173,7 @@ export default {
173173
ref: 'target',
174174
staticClass: 'scroll relative-position overflow-hidden fit',
175175
on: {
176-
wheel: this.__mouseWheel,
177-
mousewheel: this.__mouseWheel,
178-
DOMMouseScroll: this.__mouseWheel
176+
[wheelEvent.name]: this.__mouseWheel
179177
},
180178
directives: [{
181179
name: 'touch-pan',

0 commit comments

Comments
 (0)