Skip to content

Add dummy 'wheel' event handler to enable scroll zoom on safari #7474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions draftlogs/7474_fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fix scroll wheel zoom for geo subplots in Safari [#7474](https://github.com/plotly/plotly.js/pull/7474)
10 changes: 10 additions & 0 deletions src/lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ var Events = {
internalEv.emit(event, data);
};

/*
* Add a dummy event handler for 'wheel' event for Safari
* to enable mouse wheel zoom.
* https://github.com/d3/d3/issues/3035
* https://github.com/plotly/plotly.js/issues/7452
*/
if(typeof plotObj.addEventListener === 'function') {
plotObj.addEventListener("wheel", () => {});
}
Comment on lines +68 to +70
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is the if block necessary? Can plotObj be undefined?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@camdecoster There's several tests which pass an empty object ({}) as plotObj, which was leading to an error causing the test to fail.

I'm not sure if plotObj is supposed to be a DOM object or if other types are allowed.

Copy link
Contributor Author

@emilykl emilykl Jul 18, 2025

Choose a reason for hiding this comment

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

Looks like in the actual code (tests aside), Events.init() is only called in one place, and the argument is the output of getGraphDiv(), which cannot be null or undefined but it could theoretically be some other type besides a DOM element.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wonder if we should modify the tests rather than adding this if statement.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe just use the optional chaining operator? I think that would essentially do the same thing as the if block, but is more compact and you wouldn't have to update any tests.
plotObj?.addEventListener("wheel", () => {});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice, TIL.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@camdecoster I've reverted to the if statement due to the conditional chaining operator not being supported in our build pipeline (see #7477) -- are you OK with me merging as it is currently?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, this code will work fine.


return plotObj;
},

Expand Down