Skip to content

Commit

Permalink
Fix onChangeIndex is not passed when autoplay is disabled (#487)
Browse files Browse the repository at this point in the history
  • Loading branch information
getogrand authored and oliviertassinari committed Jan 19, 2019
1 parent 0190a03 commit 85f1754
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/react-swipeable-views-utils/src/autoPlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export default function autoPlay(MyComponent) {
const { index } = this.state;

if (!autoplay) {
return <MyComponent index={index} {...other} />;
return <MyComponent index={index} onChangeIndex={onChangeIndex} {...other} />;
}

return (
Expand Down
20 changes: 20 additions & 0 deletions packages/react-swipeable-views-utils/src/autoPlay.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,26 @@ describe('autoPlay', () => {
done();
}, 300);
});

it('should pass onChangeIndex also when autoplay is disabled', done => {
const handleChangeIndex = spy();

wrapper = shallow(
<AutoPlaySwipeableViews index={0} autoplay={false} onChangeIndex={handleChangeIndex}>
<div>{'slide n°1'}</div>
<div>{'slide n°2'}</div>
<div>{'slide n°3'}</div>
</AutoPlaySwipeableViews>,
);

wrapper.find(Empty).simulate('changeIndex', 1, 0);
assert.strictEqual(
handleChangeIndex.callCount,
1,
'Should be called the right number of time.',
);
done();
});
});
});
});

0 comments on commit 85f1754

Please sign in to comment.