Skip to content

Commit 00465ef

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

File tree

2 files changed

+19
-22
lines changed

2 files changed

+19
-22
lines changed

src/utils/prevent-scroll.js

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

55
let registered = 0
@@ -17,13 +17,12 @@ function shouldPreventScroll (e) {
1717

1818
const
1919
path = getEventPath(e),
20-
scrollY = Math.abs(e.deltaX) <= Math.abs(e.deltaY),
21-
testFn = scrollY ? hasScrollbar : hasScrollbarX
20+
scrollY = Math.abs(e.deltaX) <= Math.abs(e.deltaY)
2221

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

26-
if (testFn(el)) {
25+
if (hasScrollbar(el, scrollY)) {
2726
return scrollY
2827
? (
2928
e.deltaY < 0 && el.scrollTop === 0

src/utils/scroll.js

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -96,28 +96,26 @@ export function getScrollbarWidth () {
9696
return size
9797
}
9898

99-
export function hasScrollbar (el) {
99+
export function hasScrollbar (el, onY = true) {
100100
if (!el || el.nodeType !== Node.ELEMENT_NODE) {
101101
return false
102102
}
103103

104-
return el.scrollHeight > el.clientHeight && (
105-
el.classList.contains('scroll') ||
106-
el.classList.contains('overflow-auto') ||
107-
['auto', 'scroll'].includes(window.getComputedStyle(el)['overflow-y'])
108-
)
109-
}
110-
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-
)
104+
return onY
105+
? (
106+
el.scrollHeight > el.clientHeight && (
107+
el.classList.contains('scroll') ||
108+
el.classList.contains('overflow-auto') ||
109+
['auto', 'scroll'].includes(window.getComputedStyle(el)['overflow-y'])
110+
)
111+
)
112+
: (
113+
el.scrollWidth > el.clientWidth && (
114+
el.classList.contains('scroll') ||
115+
el.classList.contains('overflow-auto') ||
116+
['auto', 'scroll'].includes(window.getComputedStyle(el)['overflow-x'])
117+
)
118+
)
121119
}
122120

123121
export default {

0 commit comments

Comments
 (0)