From ce7b7e1caa59ba4084b198d9e318e6de194d0973 Mon Sep 17 00:00:00 2001 From: Stein Cato Blostrupmoen Date: Sun, 20 Mar 2016 15:31:44 +0100 Subject: [PATCH] Prevent text selection during drag --- src/InputRange/InputRange.js | 2 ++ test/InputRange.spec.js | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/InputRange/InputRange.js b/src/InputRange/InputRange.js index e93909b..6c22255 100644 --- a/src/InputRange/InputRange.js +++ b/src/InputRange/InputRange.js @@ -416,6 +416,8 @@ export default class InputRange extends React.Component { return; } + event.preventDefault(); + const key = getKeyByPosition(this, position); this.updatePosition(key, position); diff --git a/test/InputRange.spec.js b/test/InputRange.spec.js index c0f44e6..52ae6c6 100644 --- a/test/InputRange.spec.js +++ b/test/InputRange.spec.js @@ -279,9 +279,23 @@ describe('InputRange', () => { event = { clientX: 100, clientY: 200, + preventDefault: jasmine.createSpy('preventDefault'), }; }); + it('should call event.preventDefault if not disabled', () => { + inputRange.handleTrackMouseDown(event, track, position); + + expect(event.preventDefault).toHaveBeenCalledWith(); + }); + + it('should not call event.preventDefault if disabled', () => { + inputRange = renderComponent(); + inputRange.handleTrackMouseDown(event, track, position); + + expect(event.preventDefault).not.toHaveBeenCalledWith(); + }); + it('should not set a new position if disabled', () => { inputRange = renderComponent(); spyOn(inputRange, 'updatePosition');