Skip to content

Commit 2684d5b

Browse files
committed
fix: (WIP) Element in QModal doesn't scroll horizontally quasarframework#2450
1 parent 3ec7572 commit 2684d5b

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

src/utils/prevent-scroll.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getEventPath, stopAndPrevent } from './event.js'
2-
import { hasScrollbar } from './scroll.js'
2+
import { hasScrollbar, hasScrollbarX } from './scroll.js'
33
import Platform from '../plugins/platform.js'
44

55
let registered = 0
@@ -15,19 +15,26 @@ function shouldPreventScroll (e) {
1515
return true
1616
}
1717

18-
if (Math.abs(e.deltaX) > Math.abs(e.deltaY)) {
19-
return false
20-
}
21-
22-
const path = getEventPath(e)
18+
const
19+
path = getEventPath(e),
20+
scrollY = Math.abs(e.deltaX) <= Math.abs(e.deltaY),
21+
testFn = scrollY ? hasScrollbar : hasScrollbarX
2322

2423
for (let index = 0; index < path.length; index++) {
2524
const el = path[index]
2625

27-
if (hasScrollbar(el)) {
28-
return e.deltaY < 0 && el.scrollTop === 0
29-
? true
30-
: e.deltaY > 0 && el.scrollTop + el.clientHeight === el.scrollHeight
26+
if (testFn(el)) {
27+
return scrollY
28+
? (
29+
e.deltaY < 0 && el.scrollTop === 0
30+
? true
31+
: e.deltaY > 0 && el.scrollTop + el.clientHeight === el.scrollHeight
32+
)
33+
: (
34+
e.deltaX < 0 && el.scrollLeft === 0
35+
? true
36+
: e.deltaX > 0 && el.scrollLeft + el.clientWidth === el.scrollWidth
37+
)
3138
}
3239
}
3340

src/utils/scroll.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,18 @@ export function hasScrollbar (el) {
108108
)
109109
}
110110

111+
export function hasScrollbarX (el) {
112+
if (!el || el.nodeType !== Node.ELEMENT_NODE) {
113+
return false
114+
}
115+
116+
return el.scrollWidth > el.clientWidth && (
117+
el.classList.contains('scroll') ||
118+
el.classList.contains('overflow-auto') ||
119+
['auto', 'scroll'].includes(window.getComputedStyle(el)['overflow-x'])
120+
)
121+
}
122+
111123
export default {
112124
getScrollTarget,
113125
getScrollHeight,

0 commit comments

Comments
 (0)