Skip to content

Commit

Permalink
Merge "add mouse wheel listener to numbercontrollerbox" from dataarts…
Browse files Browse the repository at this point in the history
  • Loading branch information
superkelvint committed Mar 29, 2022
1 parent 09cc818 commit 7d1f13a
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/dat/controllers/NumberControllerBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class NumberControllerBox extends NumberController {

const _this = this;

const mousewheelevt = (/Firefox/i.test(navigator.userAgent)) ? 'DOMMouseScroll' : 'mousewheel';

/**
* {Number} Previous mouse y position
* @ignore
Expand Down Expand Up @@ -72,6 +74,12 @@ class NumberControllerBox extends NumberController {
prevY = e.clientY;
}

function onMouseWheel(e) {
e.preventDefault();
const direction = ((e.deltaY || -e.wheelDelta || e.detail) >> 10) || 1;
_this.setValue(_this.getValue() + direction * _this.__impliedStep);
}

function onMouseUp() {
dom.unbind(window, 'mousemove', onMouseDrag);
dom.unbind(window, 'mouseup', onMouseUp);
Expand All @@ -92,6 +100,7 @@ class NumberControllerBox extends NumberController {
dom.bind(this.__input, 'change', onChange);
dom.bind(this.__input, 'blur', onBlur);
dom.bind(this.__input, 'mousedown', onMouseDown);
dom.bind(this.__input, mousewheelevt, onMouseWheel);
dom.bind(this.__input, 'keydown', function(e) {
// When pressing enter, you can be as precise as you want.
const step = _this.__step || 1;
Expand Down

0 comments on commit 7d1f13a

Please sign in to comment.