Skip to content

Commit db0875b

Browse files
pdanpdanrstoenescu
authored andcommitted
feat(QScrollArea): Use native browser scroll instead listening for wheel/pan events - makes the scroll obey browser/os settings quasarframework#6213 (quasarframework#6238)
1 parent 5363b42 commit db0875b

File tree

2 files changed

+9
-52
lines changed

2 files changed

+9
-52
lines changed

ui/dev/src/pages/components/scroll-area.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<div class="q-layout-padding">
33
<q-toggle v-model="horizontal" label="Horizontal" />
44
<q-toggle v-model="customStyle" label="Custom style" />
5+
<q-toggle v-model="forceOnMobile" label="Force on mobile" />
56
<q-checkbox v-model="alwaysVisible" toggle-indeterminate label="Always visible" />
67

78
<div style="height: 300px;" />
@@ -13,6 +14,7 @@
1314
:visible="alwaysVisible"
1415
:bar-style="customStyle === true ? customBarStyle : void 0"
1516
:thumb-style="customStyle === true ? customThumbStyle : void 0"
17+
:force-on-mobile="forceOnMobile"
1618
>
1719
<div :class="{ 'flex no-wrap' : horizontal }">
1820
<div style="margin-top: 150px" />
@@ -47,7 +49,8 @@ export default {
4749
number: 10,
4850
horizontal: false,
4951
alwaysVisible: true,
50-
customStyle: true
52+
customStyle: true,
53+
forceOnMobile: false
5154
}
5255
},
5356

ui/src/components/scroll-area/QScrollArea.js

Lines changed: 5 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import Vue from 'vue'
22

33
import { between } from '../../utils/format.js'
4-
import { getMouseWheelDistance, prevent } from '../../utils/event.js'
54
import { setScrollPosition, setHorizontalScrollPosition } from '../../utils/scroll.js'
65
import { slot, mergeSlot } from '../../utils/slot.js'
76
import { cache } from '../../utils/vm.js'
@@ -112,8 +111,8 @@ export default Vue.extend({
112111

113112
dirProps () {
114113
return this.horizontal === true
115-
? { el: 'scrollLeft', wheel: 'x' }
116-
: { el: 'scrollTop', wheel: 'y' }
114+
? 'scrollLeft'
115+
: 'scrollTop'
117116
},
118117

119118
thumbClass () {
@@ -135,7 +134,7 @@ export default Vue.extend({
135134
getScrollPosition () {
136135
return this.$q.platform.is.desktop === true
137136
? this.scrollPosition
138-
: this.$refs.target[this.dirProps.el]
137+
: this.$refs.target[this.dirProps]
139138
},
140139

141140
setScrollPosition (offset, duration) {
@@ -196,39 +195,6 @@ export default Vue.extend({
196195
this.__setScroll(pos)
197196
},
198197

199-
__panContainer (e) {
200-
if (e.isFirst === true) {
201-
this.refPos = this.scrollPosition
202-
this.__setActive(true, true)
203-
}
204-
if (e.isFinal === true) {
205-
this.__setActive(false)
206-
}
207-
208-
const distance = e.distance[this.horizontal === true ? 'x' : 'y']
209-
const pos = this.refPos +
210-
(e.direction === this.direction ? -1 : 1) * distance
211-
212-
this.__setScroll(pos)
213-
214-
if (pos > 0 && pos + this.containerSize < this.scrollSize) {
215-
prevent(e.evt)
216-
}
217-
},
218-
219-
__mouseWheel (e) {
220-
const el = this.$refs.target
221-
222-
el[this.dirProps.el] += getMouseWheelDistance(e)[this.dirProps.wheel]
223-
224-
if (
225-
el[this.dirProps.el] > 0 &&
226-
el[this.dirProps.el] + this.containerSize < this.scrollSize
227-
) {
228-
prevent(e)
229-
}
230-
},
231-
232198
__setActive (active, timer) {
233199
clearTimeout(this.timer)
234200

@@ -258,7 +224,7 @@ export default Vue.extend({
258224
},
259225

260226
__setScroll (offset) {
261-
this.$refs.target[this.dirProps.el] = offset
227+
this.$refs.target[this.dirProps] = offset
262228
}
263229
},
264230

@@ -286,19 +252,7 @@ export default Vue.extend({
286252
}, [
287253
h('div', {
288254
ref: 'target',
289-
staticClass: 'scroll relative-position fit hide-scrollbar',
290-
on: cache(this, 'wheel', {
291-
wheel: this.__mouseWheel
292-
}),
293-
directives: cache(this, 'touch#' + this.horizontal, [{
294-
name: 'touch-pan',
295-
modifiers: {
296-
vertical: this.horizontal !== true,
297-
horizontal: this.horizontal,
298-
mightPrevent: true
299-
},
300-
value: this.__panContainer
301-
}])
255+
staticClass: 'scroll relative-position fit hide-scrollbar'
302256
}, [
303257
h('div', {
304258
staticClass: 'absolute',

0 commit comments

Comments
 (0)