Skip to content

Commit

Permalink
Ensure that slider values from nouislider are valid
Browse files Browse the repository at this point in the history
According to the nouislider docs, values are float by default, and you
must convert them as desired in the to function.

It seems that Math.round is more appropriate than Math.floor - the slider
value might be just below the appropriate value instead of just above.
  • Loading branch information
jasongrout committed Feb 1, 2022
1 parent e488987 commit 90ad74f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/controls/src/widget_int.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export abstract class BaseIntSliderView extends DescriptionView {
direction: orientation === 'horizontal' ? 'ltr' : 'rtl',
format: {
from: (value: string): number => Number(value),
to: (value: number): number => value,
to: (value: number): number => this._validate_slide_value(value),
},
});

Expand Down Expand Up @@ -285,7 +285,7 @@ export abstract class BaseIntSliderView extends DescriptionView {
* and applying it to the other views on the page.
*/
_validate_slide_value(x: number): number {
return Math.floor(x);
return Math.round(x);
}

$slider: any;
Expand Down

0 comments on commit 90ad74f

Please sign in to comment.