Skip to content

Conversation

berhalak
Copy link
Contributor

@berhalak berhalak commented Oct 1, 2025

Currently Grist detects mobile browser by looking at the UserAgent browser settings, but some browsers
hide that for security reasons.

Proposed solution

Instead of detecting the mobile platform, Grist will now check what is the primary input device or if
the screen is small enough to assume it is a mobile device.

Has this been tested?

Only manual tests on mobile browsers

@berhalak berhalak requested a review from manuhabitela October 1, 2025 10:03
// Show mobile buttons if device has narrow screen OR (touch AND coarse pointer)
return isNarrowScreen() || (hasTouchSupport && primaryPointerIsCoarse);
}

Copy link
Collaborator

@manuhabitela manuhabitela Oct 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think your logic is on-point :)

The main question coming to mind is how accurate is pointer: coarse? Like if a laptop with touch capabilities (like tablet/laptop 2-in-1 combos) is correctly detected as pointer: fine when using a mouse or not.

I can test on a laptop with a touch display later today if that helps a bit. edit: I tested and the touchscreen was correctly detected as secondary pointing device.

function needsMobileButtons(): boolean {
// Check for touch support
const hasTouchSupport = Boolean('ontouchstart' in window ||
(navigator.maxTouchPoints && navigator.maxTouchPoints > 0));
Copy link
Collaborator

@manuhabitela manuhabitela Oct 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't exclusively relying on the presence of ontouchstart be better than also having those maxTouchPoints tests?

Since hasTouchSupport is later combined with a rather recent pointer media query test, and we only support recent browsers in Grist anyway.

edit: after sleeping on it I guess I'm wrong on that and checking both pointer events and touch events is great anyway. As you wish!

Copy link
Member

@dsagal dsagal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like Manu is in agreement on detection. This seems like a good fix.

@berhalak berhalak merged commit 7fbcba0 into main Oct 7, 2025
14 of 15 checks passed
@berhalak berhalak added the preview Launch preview deployment of this PR label Oct 9, 2025
Copy link
Contributor

github-actions bot commented Oct 9, 2025

Deployed commit 62bc1744502be5d4310d32a2eb4f4a2754922ce0 as https://grist-gristlabs-grist-core-jareks-editor-buttons-for-mobile.fly.dev (until 2025-11-08T07:15:06.756Z)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
preview Launch preview deployment of this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants