diff --git a/packages/core/src/common/errors.ts b/packages/core/src/common/errors.ts index b9942c6f02..e89cd73f92 100644 --- a/packages/core/src/common/errors.ts +++ b/packages/core/src/common/errors.ts @@ -93,6 +93,8 @@ export const RADIOGROUP_WARN_CHILDREN_OPTIONS_MUTEX = export const SLIDER_ZERO_STEP = ns + ` stepSize must be greater than zero.`; export const SLIDER_ZERO_LABEL_STEP = ns + ` labelStepSize must be greater than zero.`; +export const SLIDER_MIN = ns + ` min prop must be a finite number.`; +export const SLIDER_MAX = ns + ` max prop must be a finite number.`; export const RANGESLIDER_NULL_VALUE = ns + ` value prop must be an array of two non-null numbers.`; export const MULTISLIDER_INVALID_CHILD = ns + ` children must be s or s`; export const MULTISLIDER_WARN_LABEL_STEP_SIZE_LABEL_VALUES_MUTEX = diff --git a/packages/core/src/components/slider/multiSlider.tsx b/packages/core/src/components/slider/multiSlider.tsx index a3c52d5730..a2d8eeb159 100644 --- a/packages/core/src/components/slider/multiSlider.tsx +++ b/packages/core/src/components/slider/multiSlider.tsx @@ -65,14 +65,14 @@ export interface ISliderBaseProps extends Props, IntentProps { labelPrecision?: number; /** - * Maximum value of the slider. + * Maximum value of the slider. Value must be a finite number. * * @default 10 */ max?: number; /** - * Minimum value of the slider. + * Minimum value of the slider. Value must be a finite number. * * @default 0 */ @@ -228,6 +228,12 @@ export class MultiSlider extends AbstractPureComponent2 { diff --git a/packages/core/test/slider/multiSliderTests.tsx b/packages/core/test/slider/multiSliderTests.tsx index 7c8549e5bb..10ef834692 100644 --- a/packages/core/test/slider/multiSliderTests.tsx +++ b/packages/core/test/slider/multiSliderTests.tsx @@ -334,6 +334,22 @@ describe("", () => { expectPropValidationError(MultiSlider, { labelStepSize }, "greater than zero"); }); }); + + it("throws an error if the min value is not finite", () => { + expectPropValidationError( + MultiSlider, + { min: Number.NEGATIVE_INFINITY }, + "min prop must be a finite number", + ); + }); + + it("throws an error if the max value is not finite", () => { + expectPropValidationError( + MultiSlider, + { max: Number.POSITIVE_INFINITY }, + "max prop must be a finite number", + ); + }); }); function renderSlider(joinedProps: IMultiSliderProps & { values?: [number, number, number] } = {}) {