Skip to content

Commit

Permalink
Merge pull request #561 from renancleyson-dev/indicator-select-not-re…
Browse files Browse the repository at this point in the history
…set-auto-play

#525: Fix indicator click not resetting autoplay
  • Loading branch information
leandrowd authored Mar 18, 2021
2 parents 8ed994f + acfaa1c commit 8706a7b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 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
8 changes: 2 additions & 6 deletions src/components/Carousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,7 @@ export default class Carousel extends React.Component<Props, State> {
handleClickThumb = (index: number, item: React.ReactNode) => {
this.props.onClickThumb(index, item);

this.selectItem({
selectedItem: index,
});
this.moveTo(index);
};

onSwipeStart = (event: React.TouchEvent) => {
Expand Down Expand Up @@ -684,9 +682,7 @@ export default class Carousel extends React.Component<Props, State> {

changeItem = (newIndex: number) => (e: React.MouseEvent | React.KeyboardEvent) => {
if (!isKeyboardEvent(e) || e.key === 'Enter') {
this.selectItem({
selectedItem: newIndex,
});
this.moveTo(newIndex);
}
};

Expand Down

0 comments on commit 8706a7b

Please sign in to comment.