diff --git a/packages/react-swipeable-views-core/src/checkIndexBounds.js b/packages/react-swipeable-views-core/src/checkIndexBounds.js index 9007ee87..efe5ed86 100644 --- a/packages/react-swipeable-views-core/src/checkIndexBounds.js +++ b/packages/react-swipeable-views-core/src/checkIndexBounds.js @@ -7,8 +7,8 @@ const checkIndexBounds = props => { const childrenCount = React.Children.count(children); warning( - index >= 0 && index <= childrenCount, - `react-swipeable-view: the new index: ${index} is out of bounds: [0-${childrenCount}].`, + index >= 0 && index < childrenCount, + `react-swipeable-view: the new index: ${index} is out of bounds: [0-${childrenCount - 1}].`, ); }; diff --git a/packages/react-swipeable-views-core/src/checkIndexBounds.test.js b/packages/react-swipeable-views-core/src/checkIndexBounds.test.js index 8be00318..bc37de63 100644 --- a/packages/react-swipeable-views-core/src/checkIndexBounds.test.js +++ b/packages/react-swipeable-views-core/src/checkIndexBounds.test.js @@ -28,13 +28,13 @@ describe('checkIndexBounds', () => { it('should warn when the index is out of bounds', () => { checkIndexBounds({ - index: 3, + index: 2, children, }); assert.strictEqual(consoleStub.callCount, 1); assert.strictEqual( consoleStub.args[0][0], - 'Warning: react-swipeable-view: the new index: 3 is out of bounds: [0-2].', + 'Warning: react-swipeable-view: the new index: 2 is out of bounds: [0-1].', ); }); });