From e0954ce3b13ac2fa46373cd17063ff00563b30fb Mon Sep 17 00:00:00 2001 From: PeterCharalambous <43430879+PeterCharalambous@users.noreply.github.com> Date: Wed, 22 Jan 2020 16:13:13 +1100 Subject: [PATCH 1/2] Added event listeners for touch Resolves an issue with touch screens not being able to drag the sliders --- src/Rangeslider.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Rangeslider.js b/src/Rangeslider.js index 9bd8aa1..1ab460e 100755 --- a/src/Rangeslider.js +++ b/src/Rangeslider.js @@ -106,9 +106,12 @@ class Slider extends Component { * @return {void} */ handleStart = e => { - const { onChangeStart } = this.props - document.addEventListener('mousemove', this.handleDrag) - document.addEventListener('mouseup', this.handleEnd) + const { onChangeStart } = this.props; + document.addEventListener('mousemove', this.handleDrag); + document.addEventListener('mouseup', this.handleEnd); + document.addEventListener('touchmove', _this.handleDrag); + document.addEventListener('touchend', _this.handleEnd); + this.setState( { active: true @@ -157,8 +160,10 @@ class Slider extends Component { onChangeComplete && onChangeComplete(e) } ) - document.removeEventListener('mousemove', this.handleDrag) - document.removeEventListener('mouseup', this.handleEnd) + document.removeEventListener('mousemove', this.handleDrag); + document.removeEventListener('mouseup', this.handleEnd); + document.removeEventListener('touchmove', _this.handleDrag); + document.removeEventListener('touchend', _this.handleEnd); }; /** From b863807ea835829b24d7dc2a1a07257c43d92eab Mon Sep 17 00:00:00 2001 From: PeterCharalambous <43430879+PeterCharalambous@users.noreply.github.com> Date: Wed, 22 Jan 2020 16:29:22 +1100 Subject: [PATCH 2/2] Corrected "this" --- src/Rangeslider.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Rangeslider.js b/src/Rangeslider.js index 1ab460e..564e5ee 100755 --- a/src/Rangeslider.js +++ b/src/Rangeslider.js @@ -109,8 +109,8 @@ class Slider extends Component { const { onChangeStart } = this.props; document.addEventListener('mousemove', this.handleDrag); document.addEventListener('mouseup', this.handleEnd); - document.addEventListener('touchmove', _this.handleDrag); - document.addEventListener('touchend', _this.handleEnd); + document.addEventListener('touchmove', this.handleDrag); + document.addEventListener('touchend', this.handleEnd); this.setState( { @@ -162,8 +162,8 @@ class Slider extends Component { ) document.removeEventListener('mousemove', this.handleDrag); document.removeEventListener('mouseup', this.handleEnd); - document.removeEventListener('touchmove', _this.handleDrag); - document.removeEventListener('touchend', _this.handleEnd); + document.removeEventListener('touchmove', this.handleDrag); + document.removeEventListener('touchend', this.handleEnd); }; /**