Skip to content

Commit

Permalink
Slider: allow fine-tuning via mouse wheel
Browse files Browse the repository at this point in the history
  • Loading branch information
inukshuk committed Mar 18, 2019
1 parent 365b213 commit 0d0c1d9
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/components/slider.js
Expand Up @@ -19,6 +19,7 @@ class Slider extends React.PureComponent {
track = React.createRef()

state = {
hasFocus: false,
value: 0
}

Expand Down Expand Up @@ -111,6 +112,14 @@ class Slider extends React.PureComponent {
this.set(this.getNextStep(), 'button')
}, 100)

handleBlur = () => {
this.setState({ hasFocus: false })
}

handleFocus = () => {
this.setState({ hasFocus: true })
}

handleKeyDown = (event) => {
let { value, precision, keymap, tabIndex } = this.props

Expand Down Expand Up @@ -141,6 +150,15 @@ class Slider extends React.PureComponent {
event.nativeEvent.stopImmediatePropagation()
}

handleWheel = (event) => {
if (this.state.hasFocus) {
let { value, precision } = this.props
let delta = event.deltaY || event.deltaX

this.set(value + (delta < 0 ? -1 : 1) / precision, 'wheel')
}
}

renderMinButton() {
let { min, minIcon } = this.props
let { value } = this.state
Expand Down Expand Up @@ -196,9 +214,10 @@ class Slider extends React.PureComponent {
<div
className={cx(this.classes)}
tabIndex={this.tabIndex}
onBlur={this.props.onBlur}
onFocus={this.props.onFocus}
onKeyDown={this.handleKeyDown}>
onBlur={this.handleBlur}
onFocus={this.handleFocus}
onKeyDown={this.handleKeyDown}
onWheel={this.handleWheel}>
{this.renderMinButton()}
<Draggable
delay={15}
Expand Down

0 comments on commit 0d0c1d9

Please sign in to comment.