Skip to content

Commit

Permalink
Merge pull request #1362 from FormidableLabs/bug/passive-scroll
Browse files Browse the repository at this point in the history
fix scroll wheel interaction in chrome
  • Loading branch information
boygirl authored Aug 7, 2019
2 parents 5783618 + b5a8e63 commit 81e4205
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
20 changes: 19 additions & 1 deletion packages/victory-core/src/victory-container/victory-container.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ export default class VictoryContainer extends React.Component {
this.portalUpdate = (key, el) => this.portalRef.portalUpdate(key, el);
this.portalRegister = () => this.portalRef.portalRegister();
this.portalDeregister = (key) => this.portalRef.portalDeregister(key);

this.saveContainerRef = (container) => {
this.containerRef = props.containerRef || container;
return container;
};
this.shouldHandleWheel = props.events && props.events.onWheel;
if (this.shouldHandleWheel) {
this.handleWheel = (e) => e.preventDefault();
}
}

getChildContext() {
Expand All @@ -72,10 +81,19 @@ export default class VictoryContainer extends React.Component {
};
}

componentDidMount() {
if (this.shouldHandleWheel && this.containerRef) {
this.containerRef.addEventListener("wheel", this.handleWheel);
}
}

componentWillUnmount() {
if (!this.context.getTimer) {
this.getTimer().stop();
}
if (this.shouldHandleWheel && this.containerRef) {
this.containerRef.removeEventListener("wheel", this.handleWheel);
}
}

getTimer() {
Expand Down Expand Up @@ -127,7 +145,7 @@ export default class VictoryContainer extends React.Component {
style: portalSvgStyle
};
return (
<div style={defaults({}, style, divStyle)} className={className} ref={props.containerRef}>
<div style={defaults({}, style, divStyle)} className={className} ref={this.saveContainerRef}>
<svg {...svgProps} style={svgStyle}>
{title ? <title id={this.getIdForElement("title")}>{title}</title> : null}
{desc ? <desc id={this.getIdForElement("desc")}>{desc}</desc> : null}
Expand Down
3 changes: 0 additions & 3 deletions packages/victory-zoom-container/src/victory-zoom-container.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ export const zoomContainerMixin = (base) =>
},
// eslint-disable-next-line max-params
onWheel: (evt, targetProps, eventKey, ctx) => {
if (targetProps.allowZoom && !props.disable) {
evt.preventDefault();
}
return props.disable ? {} : ZoomHelpers.onWheel(evt, targetProps, eventKey, ctx);
}
}
Expand Down

0 comments on commit 81e4205

Please sign in to comment.