Skip to content

Commit

Permalink
#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 15, 2021
1 parent 6378163 commit 2d0c779
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/__tests__/Carousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,20 @@ describe('Slider', function() {

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

it('should reset when changing the slide through indicator', () => {
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 2d0c779

Please sign in to comment.