Skip to content

Commit ad5e02a

Browse files
DEV: Use media query for capabilities.touch (#32620)
This will allow us to have perfect consistency with CSS-based touch detection
1 parent b2d0ec0 commit ad5e02a

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

app/assets/javascripts/discourse/app/services/capabilities.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ const breakpointQueries = {
1414
"2xl": new TrackedMediaQuery("(min-width: 96rem)"),
1515
};
1616

17-
class Capabilities {
18-
touch = navigator.maxTouchPoints > 1 || "ontouchstart" in window;
17+
const anyPointerCourseQuery = new TrackedMediaQuery("(any-pointer: coarse)");
1918

19+
class Capabilities {
2020
isAndroid = ua.includes("Android");
2121
isWinphone = ua.includes("Windows Phone");
2222
isIpadOS = ua.includes("Mac OS") && !/iPhone|iPod/.test(ua) && this.touch;
@@ -66,6 +66,10 @@ class Capabilities {
6666
},
6767
};
6868

69+
get touch() {
70+
return anyPointerCourseQuery.matches;
71+
}
72+
6973
get userHasBeenActive() {
7074
return (
7175
!("userActivation" in navigator) || navigator.userActivation.hasBeenActive

0 commit comments

Comments
 (0)