Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#517: Fix emulated touch never changing slide #556

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/__tests__/Carousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,29 @@ describe('Slider', function() {
expect(swipeProps.onSwipeDown).toBe(componentInstance.onSwipeForward);
});
});

describe('emulateTouch', () => {
it('should cancel click when swipe forward and backwards with emulated touch', () => {
renderDefaultComponent({
emulateTouch: true,
});

let currentIndex = componentInstance.state.selectedItem;
const items = componentInstance.props.children;

componentInstance.onSwipeForward();
componentInstance.handleClickItem(currentIndex, items[currentIndex]);
++currentIndex;

expect(componentInstance.state.selectedItem).toEqual(currentIndex);

componentInstance.onSwipeBackwards();
componentInstance.handleClickItem(currentIndex, items[currentIndex]);
--currentIndex;

expect(componentInstance.state.selectedItem).toEqual(currentIndex);
});
});
});

describe('center mode', () => {
Expand Down
8 changes: 8 additions & 0 deletions src/components/Carousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -665,10 +665,18 @@ export default class Carousel extends React.Component<Props, State> {

onSwipeForward = () => {
this.increment(1, true);

if (this.props.emulateTouch) {
this.setState({ cancelClick: true });
}
};

onSwipeBackwards = () => {
this.decrement(1, true);

if (this.props.emulateTouch) {
this.setState({ cancelClick: true });
}
};

changeItem = (newIndex: number) => (e: React.MouseEvent | React.KeyboardEvent) => {
Expand Down