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 4f8c830
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/panAndZoomHoc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export default function panAndZoom<P>(WrappedComponent: React.SFC<P> | React.Com
onPanMove: PropTypes.func,
onPanEnd: PropTypes.func,
onZoom: PropTypes.func,
onPanAndZoom: PropTypes.func
onPanAndZoom: PropTypes.func,
ref: PropTypes.func
};

static defaultProps = {
Expand Down Expand Up @@ -68,13 +69,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 +277,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 4f8c830

Please sign in to comment.