Skip to content

fix: let the page scroll in the direction touch gestures do not use - #1007

Merged
kurkle merged 2 commits into
chartjs:masterfrom
kurkle:fix/touch-action
Nov 21, 2026
Merged

kurkle merged 2 commits into
chartjs:masterfrom
kurkle:fix/touch-action

Conversation

@kurkle

@kurkle kurkle commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

With pan or pinch enabled the canvas always got touch-action: none, so a chart that only pans along x still swallowed vertical swipes, and a chart filling a phone screen left no way to scroll the page.

The plugin now claims only the directions its touch gestures can act on: pan.mode and pan.scaleMode when panning is enabled, and zoom.mode when pinch is enabled:

Directions used touch-action
x only pan-y
y only pan-x
both none (as before)

The browser's own pinch zoom stays off in every case, and the value is refreshed on each chart update because the mode can be a function. The default mode is xy, so charts that do not set a mode behave as before.

Verification

Besides the specs for the style value, I drove real touch input through the DevTools protocol in Chromium (mobile emulation, built UMD bundle, a page taller than the viewport):

Options Gesture Page scrolled Chart
pan x vertical swipe 163 px unchanged
pan x horizontal swipe 0 panned
pan x diagonal, mostly horizontal 0 panned
pan xy vertical swipe 0 panned along y
pan x + pinch x vertical swipe 163 px unchanged
pan x + pinch x horizontal pinch 0 zoomed
pan x + pinch x diagonal pinch 0 zoomed
pan x + pinch x two-finger vertical drag 0 unchanged (within 1%)

Not verified on Safari or on physical devices.

Of the two things #791 reports, this fixes the vertical drag being ignored. A pinch over the chart still zooms the chart and not the page when pinch zooming is enabled; that is what the option asks for, and the page can now be scrolled away from the chart.

Fixes #336
Fixes #791

With pan or pinch enabled the canvas always got `touch-action: none`,
so a chart that only pans along x still swallowed vertical swipes. On a
phone a chart that fills the screen left no way to scroll the page.

The plugin now claims only the directions its touch gestures can act
on, taken from `pan.mode` and, when pinch is enabled, `zoom.mode`:
`pan-y` when they are limited to x, `pan-x` when limited to y, and
`none` as before when both are used. The value follows the mode on
every chart update, since the mode can be a function.
A pan that starts over a scale follows `pan.scaleMode` whatever
`pan.mode` says, so `mode: 'x'` with `scaleMode: 'y'` pans along y over
the y axis. Deriving the touch action from the mode alone handed that
swipe to the browser. The scale mode now counts as a used direction.

A pinch only zooms along `zoom.mode`, also over a scale, so it needs no
such addition.

The documentation names the options the value comes from, and says that
the browser's pinch zoom stays off over the chart.
@kurkle
kurkle marked this pull request as ready for review November 21, 2026 19:11
@kurkle
kurkle requested a review from etimberg November 21, 2026 19:21
@kurkle
kurkle merged commit 82a51c2 into chartjs:master Nov 21, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Zooming in breaks scrolling on mobile device Allow normal touch scroll when pan.mode = 'x'

2 participants