Skip to content

Instantly share code, notes, and snippets.

@bpierre

bpierre/.diff Secret

Created August 25, 2018 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bpierre/132604bcd177a9ed0a1678509cdb65e1 to your computer and use it in GitHub Desktop.
Save bpierre/132604bcd177a9ed0a1678509cdb65e1 to your computer and use it in GitHub Desktop.
diff --git a/src/components/Slider/Slider.js b/src/components/Slider/Slider.js
index fb2598f..b83f404 100644
--- a/src/components/Slider/Slider.js
+++ b/src/components/Slider/Slider.js
@@ -28,6 +28,7 @@ class Slider extends React.Component {
}
handleRef = element => {
this._mainElement = element
+ this._document = element.ownerDocument
}
getRect = () => {
const now = Date.now()
@@ -58,17 +59,17 @@ class Slider extends React.Component {
this.setState({ pressed: true }, () => {
this.updateValueFromClientX(clientX)
})
- document.addEventListener('mouseup', this.dragStop)
- document.addEventListener('touchend', this.dragStop)
- document.addEventListener('mousemove', this.dragMove)
- document.addEventListener('touchmove', this.dragMove)
+ this._document.addEventListener('mouseup', this.dragStop)
+ this._document.addEventListener('touchend', this.dragStop)
+ this._document.addEventListener('mousemove', this.dragMove)
+ this._document.addEventListener('touchmove', this.dragMove)
}
dragStop = () => {
this.setState({ pressed: false })
- document.removeEventListener('mouseup', this.dragStop)
- document.removeEventListener('touchend', this.dragStop)
- document.removeEventListener('mousemove', this.dragMove)
- document.removeEventListener('touchmove', this.dragMove)
+ this._document.removeEventListener('mouseup', this.dragStop)
+ this._document.removeEventListener('touchend', this.dragStop)
+ this._document.removeEventListener('mousemove', this.dragMove)
+ this._document.removeEventListener('touchmove', this.dragMove)
}
dragMove = event => {
if (!this.state.pressed) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment