Skip to content

feat: provide raw deltaX/deltaY/deltaMode in the mousewheel event#1162

Open
takaebato wants to merge 1 commit into
ecomfe:masterfrom
takaebato:feat/wheel-event-raw-delta
Open

feat: provide raw deltaX/deltaY/deltaMode in the mousewheel event#1162
takaebato wants to merge 1 commit into
ecomfe:masterfrom
takaebato:feat/wheel-event-raw-delta

Conversation

@takaebato

@takaebato takaebato commented Jul 11, 2026

Copy link
Copy Markdown

What does this PR do

Exposes the raw deltaX / deltaY / deltaMode of the native WheelEvent on ElementEvent (resolves the TODO in src/core/event.ts).

zr.on('mousewheel', (e) => {
    e.deltaX;      // raw WheelEvent.deltaX
    e.deltaY;      // raw WheelEvent.deltaY
    e.deltaMode;   // raw WheelEvent.deltaMode (0: pixel, 1: line, 2: page)
    e.wheelDelta;  // unchanged
});

Motivation

The normalized wheelDelta ignores deltaMode, so its scale differs among browsers and devices (e.g. Chrome reports pixels, Firefox reports lines).
With the raw values, downstream consumers (e.g. ECharts RoamController) can precisely tune scroll/zoom sensitivity per device, without casting e.event to WheelEvent.

Design notes

  • Raw pass-through — no normalization, no polyfill. undefined on non-wheel events and on legacy browsers (hence optional in the type).
  • zrDelta / wheelDelta are untouched; fully backward compatible.

Feedback wanted

  • The new props have no fallback: on browsers that do not implement WheelEvent they stay undefined (hence optional in the type). This differs from existing props like offsetX / which, which fall back to computed values when the native prop is missing. Let me know if a fallback is preferred.
  • The props are added to the existing "mousewheel" event. An alternative would be a new spec-aligned "wheel" event; I kept the change small in this PR.
  • DOM_DELTA_* constants are not exported: consumers (e.g. ECharts) are expected to reference WheelEvent.DOM_DELTA_* directly inside their event handlers. Let me know if zrender should provide them alongside deltaMode.

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.

1 participant