Skip to content

Commit d72d899

Browse files
authored
Prevent negative slide number (#249)
1 parent 5d1c8ac commit d72d899

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/CarouselProvider/CarouselProvider.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ const CarouselProvider = class CarouselProvider extends React.Component {
140140
}
141141

142142
if (this.carouselStore.state.currentSlide >= this.props.totalSlides) {
143-
newStoreState.currentSlide = this.props.totalSlides - 1;
143+
newStoreState.currentSlide = Math.max(this.props.totalSlides - 1, 0);
144144
}
145145

146146
if (Object.keys(newStoreState).length > 0) {

src/CarouselProvider/__tests__/CarouselProvider.test.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ describe('<CarouselProvider />', () => {
7373
expect(start.currentSlide).toEqual(end.currentSlide);
7474
expect(start.disableAnimation).toEqual(end.disableAnimation);
7575
});
76-
it('should set disableAnimation to true and privatUnDisableAnimation to true if we updated currentSlide prop on CarouselProvider component', async () => {
76+
it('should set disableAnimation to true and privateUnDisableAnimation to true if we updated currentSlide prop on CarouselProvider component', async () => {
7777
const wrapper = mount(
7878
<CarouselProvider {...props}>Hello</CarouselProvider>,
7979
);
@@ -83,7 +83,7 @@ describe('<CarouselProvider />', () => {
8383
true,
8484
);
8585
});
86-
it('The Slider component should reset disableAnimation to false and privatUnDisableAnimation to false if when Slider component is updated', async () => {
86+
it('The Slider component should reset disableAnimation to false and privateUnDisableAnimation to false if when Slider component is updated', async () => {
8787
const wrapper = mount(
8888
<CarouselProvider {...props}>
8989
<Slider>Hello</Slider>
@@ -103,7 +103,7 @@ describe('<CarouselProvider />', () => {
103103
);
104104
expect(wrapper.instance().getStore().state.isIntrinsicHeight).toBe(true);
105105
});
106-
it('should throw an error, when tryng to use isIntrinsicHeight in vertical orientation', async () => {
106+
it('should throw an error, when trying to use isIntrinsicHeight in vertical orientation', async () => {
107107
expect(() => shallow(
108108
<CarouselProvider {...props} isIntrinsicHeight orientation="vertical">
109109
test

0 commit comments

Comments
 (0)