Skip to content

Commit

Permalink
fix onWheel preventDefault() on Chrome >= v73
Browse files Browse the repository at this point in the history
  • Loading branch information
Fonger committed Apr 3, 2019
1 parent 55c5812 commit b44359c
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/panAndZoomHoc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,24 @@ export default function panAndZoom<P>(WrappedComponent: React.SFC<P> | React.Com
}
}

componentRef = React.createRef<HTMLElement>();

componentDidMount() {
if (this.componentRef.current) {
this.componentRef.current.addEventListener('wheel', this.handleWheel);
}
}

componentWillUnmount() {
if (this.panning) {
document.removeEventListener('mousemove', this.handleMouseMove);
document.removeEventListener('mouseup', this.handleMouseUp);
document.removeEventListener('touchmove', this.handleMouseMove);
document.removeEventListener('touchend', this.handleMouseUp);
}
if (this.componentRef.current) {
this.componentRef.current.removeEventListener('wheel', this.handleWheel);
}
}

handleWheel = (event: WheelEvent) => {
Expand Down Expand Up @@ -265,9 +276,9 @@ export default function panAndZoom<P>(WrappedComponent: React.SFC<P> | React.Com
<WrappedComponent
{...passedProps}
{...other}
ref={this.componentRef}
onMouseDown={this.handleMouseDown}
onTouchStart={this.handleMouseDown}
onWheel={this.handleWheel}
>
{children}
</WrappedComponent>
Expand Down

0 comments on commit b44359c

Please sign in to comment.