Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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