Skip to content

Commit 4850828

Browse files
authored
fix: null value should not out of range (#640)
1 parent 9a3c76f commit 4850828

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/common/createSlider.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ export default function createSlider(Component) {
239239
calcOffset(value) {
240240
const { min, max } = this.props;
241241
const ratio = (value - min) / (max - min);
242-
return ratio * 100;
242+
return Math.max(0, ratio * 100);
243243
}
244244

245245
saveSlider = (slider) => {

tests/Slider.test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,4 +356,9 @@ describe('Slider', () => {
356356
expect(handleBlur).toBeCalled();
357357
});
358358
});
359+
360+
it('should not be out of range when value is null', () => {
361+
const wrapper = mount(<Slider value={null} min={1} max={10} />);
362+
expect(wrapper.find('Track').props().length >= 0).toBeTruthy();
363+
});
359364
});

0 commit comments

Comments
 (0)