Skip to content

Commit

Permalink
fix: change event binding to slider ownerDocument (#326)
Browse files Browse the repository at this point in the history
* change event binding to slider ownerDocument

* Refactoring. Take out ownerDocument to this.document
  • Loading branch information
zvcolpdy authored and benjycui committed Oct 18, 2017
1 parent b321edd commit aae0498
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/common/createSlider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ export default function createSlider(Component) {
this.removeDocumentEvents();
}

componentDidMount() {
this.document = this.sliderRef.ownerDocument;
}

onMouseDown = (e) => {
if (e.button !== 0) { return; }

Expand Down Expand Up @@ -138,13 +142,13 @@ export default function createSlider(Component) {

addDocumentTouchEvents() {
// just work for Chrome iOS Safari and Android Browser
this.onTouchMoveListener = addEventListener(document, 'touchmove', this.onTouchMove);
this.onTouchUpListener = addEventListener(document, 'touchend', this.onEnd);
this.onTouchMoveListener = addEventListener(this.document, 'touchmove', this.onTouchMove);
this.onTouchUpListener = addEventListener(this.document, 'touchend', this.onEnd);
}

addDocumentMouseEvents() {
this.onMouseMoveListener = addEventListener(document, 'mousemove', this.onMouseMove);
this.onMouseUpListener = addEventListener(document, 'mouseup', this.onEnd);
this.onMouseMoveListener = addEventListener(this.document, 'mousemove', this.onMouseMove);
this.onMouseUpListener = addEventListener(this.document, 'mouseup', this.onEnd);
}

removeDocumentEvents() {
Expand Down

0 comments on commit aae0498

Please sign in to comment.