Skip to content

Commit

Permalink
fix(frontend): keyboard controls for parameter sliders (#640)
Browse files Browse the repository at this point in the history
Fix parameter sliders, in simulation plots, so that they can be controlled from the keyboard. Left/right cursor keys for fine control. Shift+left/right cursor keys for coarse control.
  • Loading branch information
eatyourgreens authored Jan 20, 2025
1 parent 49e3bc3 commit b293ac3
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions frontend-v2/src/features/simulation/SimulationSliderView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ const SimulationSliderView: FC<SimulationSliderProps> = ({
);
const stepValue = (maxValue - minValue) / 1000.0;

const handleBlur = () => {
const commitChanges = () => {
setEditing(false);
let truncatedValue = value;
if (value < minValue) {
Expand Down Expand Up @@ -231,8 +231,10 @@ const SimulationSliderView: FC<SimulationSliderProps> = ({
min={minValue}
max={maxValue}
step={stepValue}
shiftStep={stepValue * 10}
onChange={handleSliderChange}
onChangeCommitted={handleBlur}
onPointerUp={commitChanges}
onKeyUp={commitChanges}
valueLabelDisplay="off"
aria-labelledby="input-slider"
/>
Expand All @@ -243,7 +245,7 @@ const SimulationSliderView: FC<SimulationSliderProps> = ({
value={formatNumber(value)}
size="small"
onChange={handleInputChange}
onBlur={handleBlur}
onBlur={commitChanges}
inputProps={{
step: stepValue,
min: minValue,
Expand Down

0 comments on commit b293ac3

Please sign in to comment.