Skip to content

Commit

Permalink
feat: add support for Page Up and Page Down keys
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Stone authored and stonebk committed Sep 27, 2019
1 parent e8c8e1f commit ed67408
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/components/ReactSlider/ReactSlider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -378,21 +378,29 @@ class ReactSlider extends React.Component {
case 'ArrowLeft':
case 'ArrowDown':
e.preventDefault();
this.moveDownOneStep();
return;
this.moveDownBySteps();
break;
case 'ArrowRight':
case 'ArrowUp':
e.preventDefault();
this.moveUpOneStep();
return;
this.moveUpBySteps();
break;
case 'Home':
e.preventDefault();
this.move(this.props.min);
return;
break;
case 'End':
e.preventDefault();
this.move(this.props.max);
break;
case 'PageDown':
e.preventDefault();
this.moveDownBySteps(10);
break;
case 'PageUp':
e.preventDefault();
this.moveUpBySteps(10);
break;
default:
}
};
Expand Down Expand Up @@ -643,15 +651,15 @@ class ReactSlider extends React.Component {
}));
}

moveUpOneStep() {
moveUpBySteps(steps = 1) {
const oldValue = this.state.value[this.state.index];
const newValue = oldValue + this.props.step;
const newValue = oldValue + this.props.step * steps;
this.move(Math.min(newValue, this.props.max));
}

moveDownOneStep() {
moveDownBySteps(steps = 1) {
const oldValue = this.state.value[this.state.index];
const newValue = oldValue - this.props.step;
const newValue = oldValue - this.props.step * steps;
this.move(Math.max(newValue, this.props.min));
}

Expand Down

0 comments on commit ed67408

Please sign in to comment.