Skip to content

Commit

Permalink
leandrowd#525: Fix indicator click not resetting autoplay
Browse files Browse the repository at this point in the history
  • Loading branch information
renancleyson-dev committed Feb 16, 2021
1 parent 6378163 commit 2f8b575
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/__tests__/Carousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,21 @@ describe('Slider', function() {

expect(componentInstance.state.selectedItem).toBe(2);
});

it('should reset when changing the slide through indicator', () => {
renderDefaultComponent({ interval: 3000, autoPlay: true });
jest.advanceTimersByTime(2000);

expect(componentInstance.state.selectedItem).toBe(0);

const changeToSecondItem = componentInstance.changeItem(1);
// it only runs with an event
changeToSecondItem(new MouseEvent('click'));

jest.advanceTimersByTime(1000);

expect(componentInstance.state.selectedItem).toBe(1);
});
});

describe('Infinite Loop and Auto Play', () => {
Expand Down
4 changes: 4 additions & 0 deletions src/components/Carousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,10 @@ export default class Carousel extends React.Component<Props, State> {
this.selectItem({
selectedItem: newIndex,
});

if (this.state.autoPlay) {
this.resetAutoPlay();
}
}
};

Expand Down

0 comments on commit 2f8b575

Please sign in to comment.