Skip to content

Commit 8460a60

Browse files
authored
Merge pull request #74 from sag1v/support-decimal-items-toShow
support decimals itemsToShow
2 parents 2cff8bd + fb0cace commit 8460a60

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/react-elastic-carousel/components/Carousel.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,10 @@ class Carousel extends React.Component {
260260

261261
convertChildToCbObj = index => {
262262
const { children } = this.props;
263-
const child = children[index];
264-
return { item: child.props, index };
263+
// support decimal itemsToShow
264+
const roundedIdx = Math.round(index);
265+
const child = children[roundedIdx];
266+
return { item: child.props, index: roundedIdx };
265267
};
266268

267269
getNextItemIndex = (currentIndex, getPrev) => {
@@ -285,8 +287,10 @@ class Carousel extends React.Component {
285287
const { children } = this.props;
286288
const { firstItem } = this.state;
287289
const nextItemIndex = this.getNextItemIndex(firstItem, getPrev);
288-
const asElement = children[nextItemIndex];
289-
const asObj = { item: asElement.props, index: nextItemIndex };
290+
// support decimal itemsToShow
291+
const roundedIdx = Math.round(nextItemIndex);
292+
const asElement = children[roundedIdx];
293+
const asObj = { item: asElement.props, index: roundedIdx };
290294
return asObj;
291295
};
292296

0 commit comments

Comments
 (0)