Skip to content

Commit

Permalink
[core] fix(Slider): error if min/max are not finite (#5964)
Browse files Browse the repository at this point in the history
  • Loading branch information
akatcha authored Feb 21, 2023
1 parent 4cbc9e1 commit 743fcfd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/core/src/common/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ export const RADIOGROUP_WARN_CHILDREN_OPTIONS_MUTEX =

export const SLIDER_ZERO_STEP = ns + ` <Slider> stepSize must be greater than zero.`;
export const SLIDER_ZERO_LABEL_STEP = ns + ` <Slider> labelStepSize must be greater than zero.`;
export const SLIDER_MIN = ns + ` <Slider> min prop must be a finite number.`;
export const SLIDER_MAX = ns + ` <Slider> max prop must be a finite number.`;
export const RANGESLIDER_NULL_VALUE = ns + ` <RangeSlider> value prop must be an array of two non-null numbers.`;
export const MULTISLIDER_INVALID_CHILD = ns + ` <MultiSlider> children must be <SliderHandle>s or <SliderTrackStop>s`;
export const MULTISLIDER_WARN_LABEL_STEP_SIZE_LABEL_VALUES_MUTEX =
Expand Down
10 changes: 8 additions & 2 deletions packages/core/src/components/slider/multiSlider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -228,6 +228,12 @@ export class MultiSlider extends AbstractPureComponent2<MultiSliderProps, ISlide
if (props.labelStepSize !== undefined && props.labelStepSize! <= 0) {
throw new Error(Errors.SLIDER_ZERO_LABEL_STEP);
}
if (props.min !== undefined && !isFinite(props.min)) {
throw new Error(Errors.SLIDER_MIN);
}
if (props.max !== undefined && !isFinite(props.max)) {
throw new Error(Errors.SLIDER_MAX);
}

let anyInvalidChildren = false;
React.Children.forEach(props.children, child => {
Expand Down
16 changes: 16 additions & 0 deletions packages/core/test/slider/multiSliderTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,22 @@ describe("<MultiSlider>", () => {
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] } = {}) {
Expand Down

1 comment on commit 743fcfd

@adidahiya
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[core] fix(Slider): error if min/max are not finite (#5964)

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

Please sign in to comment.