Skip to content

Commit

Permalink
fix(util): Update inputtype determination code
Browse files Browse the repository at this point in the history
Apply to fix weired evaluation from the browser.
Same logic splitted into two different condition, where
evaluating within Array.some() give different result.

Fix #3798
  • Loading branch information
netil authored Jun 7, 2024
1 parent c3cdfaa commit f6201ad
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/module/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -835,8 +835,7 @@ function convertInputType(mouse: boolean, touch: boolean): "mouse" | "touch" | n
// Check if agent has mouse using any-hover, touch devices (e.g iPad) with external mouse will return true as long as mouse is connected
// https://css-tricks.com/interaction-media-features-and-their-potential-for-incorrect-assumptions/#aa-testing-the-capabilities-of-all-inputs
// Demo: https://patrickhlauke.github.io/touch/pointer-hover-any-pointer-any-hover/
const hasMouse = mouse && ["any-hover:hover", "any-pointer:fine"]
.some(v => matchMedia?.(`(${v})`).matches);
const hasMouse = mouse && (matchMedia?.("any-hover:hover").matches || matchMedia?.("any-pointer:fine").matches);

// fallback to 'mouse' if no input type is detected.
return (hasMouse && "mouse") || (hasTouch && "touch") || "mouse";
Expand Down

0 comments on commit f6201ad

Please sign in to comment.