Skip to content

Conversation

JCQuintas
Copy link
Member

@JCQuintas JCQuintas commented Sep 26, 2025

Fixes #18955

I went with a custom TapAndDragGesture rather than relying on the TapGesture and PanGesture directly, as they would interfere with other behaviours. (Eg: if user is panning but the tapAndDrag changed the drag config, the original pan would stop working)

Internally we are instantiating a new TapGesture and a new PanGesture and augmenting their behaviour, rather than reimplementing/copy-pasting the tap and drag behaviours in a single gesture.

https://deploy-preview-19727--material-ui-x.netlify.app/x/react-charts/zoom-and-pan/#interactions

Changelog

  • The chart zoom now supports the tapAndDrag gesture. Zoom in/out by tapping twice and dragging vertically.

@JCQuintas JCQuintas self-assigned this Sep 26, 2025
@JCQuintas JCQuintas added the type: new feature Expand the scope of the product to solve a new problem. label Sep 26, 2025
@JCQuintas JCQuintas added plan: Pro Impact at least one Pro user. scope: charts Changes related to the charts. labels Sep 26, 2025
@mui-bot
Copy link

mui-bot commented Sep 26, 2025

Deploy preview: https://deploy-preview-19727--material-ui-x.netlify.app/

Updated pages:

Bundle size report

Bundle Parsed size Gzip size
@mui/x-data-grid 0B(0.00%) 0B(0.00%)
@mui/x-data-grid-pro 0B(0.00%) 0B(0.00%)
@mui/x-data-grid-premium 0B(0.00%) 0B(0.00%)
@mui/x-charts 🔺+4.49KB(+1.37%) 🔺+635B(+0.63%)
@mui/x-charts-pro 🔺+5.3KB(+1.26%) 🔺+719B(+0.54%)
@mui/x-charts-premium 🔺+5.3KB(+1.25%) 🔺+720B(+0.55%)
@mui/x-date-pickers 0B(0.00%) 0B(0.00%)
@mui/x-date-pickers-pro 0B(0.00%) 0B(0.00%)
@mui/x-tree-view 0B(0.00%) 0B(0.00%)
@mui/x-tree-view-pro 0B(0.00%) 0B(0.00%)

Details of bundle changes

Generated by 🚫 dangerJS against d45201a

Copy link

codspeed-hq bot commented Sep 27, 2025

CodSpeed Instrumentation Performance Report

Merging #19727 will not alter performance

Comparing JCQuintas:tap-and-pan (d45201a) with master (943e431)1

Summary

✅ 12 untouched

Footnotes

  1. No successful run was found on master (8562aef) during the generation of this report, so 943e431 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.


- **`wheel`**: Zoom in/out by scrolling the mouse wheel (default)
- **`pinch`**: Zoom in/out by pinching on touch devices (default)
- **`tapAndDrag`**: Zoom in/out by tapping once and then dragging vertically. Dragging up zooms in, dragging down zooms out.
Copy link
Member

@bernardobelchior bernardobelchior Sep 29, 2025

Choose a reason for hiding this comment

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

I think of this a "double tap and drag", since you tap once, then you lift the finger and tap a second time before dragging.

So, "doubleTapAndDrag" would better describe the action, and some people do call it "double tap and drag" (here and here, here).

The only place I saw it called "tap-and-drag" was here, but the description then mentions a double tap:

Tap-and-drag is performed by double tapping anywhere on the display.

So, we can either:

  1. Rename it to doubleTapAndDrag or,
  2. Update the description here to say "[...] by tapping twice [...]"

I'm fine either way.

Copy link
Member Author

Choose a reason for hiding this comment

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

thats odd, I wouldn't consider it a double-tap because our tap interaction is defined as a down+up interaction, and in this case it is down+up/down+move, in my understanding a double tap would be down+up/down+up/down+move. We don't say the drag is a tap and drag interaction.

I'm ok with changing if you still think that should be the case

Copy link
Member

Choose a reason for hiding this comment

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

We don't say the drag is a tap and drag interaction.

True. I agree there is some inconsistency.

I think we can keep the name, but I'd update the description to say "tapping twice". Maybe even call out "similar to Google/Apple Maps"? What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

updated

Copy link
Member Author

Choose a reason for hiding this comment

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

@bernardobelchior added a prevent default for touchstart when we detect the tap. Safari has this behaviour by default when you taptap, and there is not a lot of ways to get rid of it.

If we always prevent the default, then the touch-action: pan-y wouldn't work. So we add/remove this listener at the same stage we used to add/remove the touchAction changes I did a few commits ago

Copy link
Member

Choose a reason for hiding this comment

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

It's now working perfectly, great job!

@prakhargupta1
Copy link
Member

prakhargupta1 commented Sep 29, 2025

I have a fundamental question about this gesture/feature. Since this is only applicable for touch screen devices, why would someone do this when they can pinch to zoom and drag to pan. These feel more intuitive to me.

Also, does Google maps support this? I couldn't replicate it on my phone.

@bernardobelchior
Copy link
Member

Also, does Google map support this? I couldn't replicate it on my phone.

Yes, Apple Maps as well.

@prakhargupta1
Copy link
Member

prakhargupta1 commented Sep 29, 2025

Yes, Apple Maps as well.

Got it, yes just checked it both on apple and google maps. I have never used this gesture, but ok this seems to be there for accessibility. Also, as Bernardo pointed out, they describe it as "double tap and drag".

Copy link
Member

@bernardobelchior bernardobelchior left a comment

Choose a reason for hiding this comment

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

The interaction is looking great! Nice job 💯

@JCQuintas JCQuintas merged commit 7ed4c14 into mui:master Oct 1, 2025
22 checks passed
@JCQuintas JCQuintas deleted the tap-and-pan branch October 1, 2025 07:19
@JCQuintas JCQuintas changed the title [charts] Add tapAndDrag zoom gesture [charts-pro] Add tapAndDrag zoom gesture Oct 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plan: Pro Impact at least one Pro user. scope: charts Changes related to the charts. type: new feature Expand the scope of the product to solve a new problem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[charts] Add onTapAndDrag zoom gesture
6 participants