Skip to content

Commit

Permalink
JSWindow: Use native wheel event listener to preventDefault
Browse files Browse the repository at this point in the history
  • Loading branch information
AmaanC committed Apr 1, 2020
1 parent 4712122 commit 1a8d3cb
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/JSWindow/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,11 @@ export class JSWindow extends Component<WindowProps, State> {
}
if (this.props.active!) this.foreground();
this.update();

this.onWheel = this.onWheel.bind(this);
if (this.clientRef.current) {
this.clientRef.current.addEventListener('wheel', this.onWheel);
}
}
/**
*React componentWillUnmount
Expand All @@ -240,6 +245,10 @@ export class JSWindow extends Component<WindowProps, State> {
node.removeEventListener("move", this.onMove.bind(this));
node.removeEventListener("active", this.onActive.bind(this));
}

if (this.clientRef.current) {
this.clientRef.current.removeEventListener('wheel', this.onWheel);
}
}
public componentDidUpdate() {
if (this.props.onUpdate) {
Expand Down Expand Up @@ -451,7 +460,6 @@ export class JSWindow extends Component<WindowProps, State> {
Width={clientWidth}
Height={clientHeight}
style={this.props.clientStyle!}
onWheel={this.onWheel.bind(this)}
onMouseMove={this.onMouseMove.bind(this)}
>
<div ref={this.zoomRef} style={{
Expand Down Expand Up @@ -859,11 +867,10 @@ export class JSWindow extends Component<WindowProps, State> {
}});
}

private onWheel(evt: React.MouseEvent) {
evt.stopPropagation();

const e: any = evt.nativeEvent;
private onWheel(e: any) {
e.stopPropagation();
if ((e.ctrlKey === true || e.altKey === true) && e.deltaY) {
e.preventDefault();
this.zoom(-Math.sign(e.deltaY), e.pageX, e.pageY);
}
}
Expand Down

0 comments on commit 1a8d3cb

Please sign in to comment.