Skip to content

Commit 2a4dffb

Browse files
authored
Merge pull request #85 from sag1v/fix-tabindex
resolve 84
2 parents 6c5c9c1 + ff51a97 commit 2a4dffb

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,10 @@ class Carousel extends React.Component {
160160
return currentBreakPoint;
161161
};
162162

163-
getNumOfVisibleItems = () => {
163+
/** We might get itemsToShow as a direct prop
164+
** Or we might get it as a prop inside a selected breakpoint.
165+
***/
166+
getCalculatedItemsToShow = () => {
164167
const { itemsToShow } = this.props;
165168
let visibleItems = itemsToShow;
166169

@@ -171,6 +174,9 @@ class Carousel extends React.Component {
171174
return visibleItems;
172175
};
173176

177+
/** We might get itemsToScroll as a direct prop
178+
** Or we might get it as a prop inside a selected breakpoint.
179+
***/
174180
getItemsToScroll = () => {
175181
const { itemsToScroll } = this.props;
176182
const currentBreakPoint = this.getCurrentBreakpoint();
@@ -186,7 +192,7 @@ class Carousel extends React.Component {
186192
const { children, verticalMode } = props;
187193
const { childWidth, childHeight, firstItem } = state;
188194
const totalItems = children.length;
189-
const numOfVisibleItems = this.getNumOfVisibleItems();
195+
const numOfVisibleItems = this.getCalculatedItemsToShow();
190196
const hiddenSlots = totalItems - numOfVisibleItems;
191197
let moveBy = firstItem * -1;
192198
const emptySlots = numOfVisibleItems - (totalItems - firstItem);
@@ -207,7 +213,7 @@ class Carousel extends React.Component {
207213
const { height } = sliderNode.contentRect;
208214
const nextState = {};
209215
if (verticalMode) {
210-
const numOfVisibleItems = this.getNumOfVisibleItems();
216+
const numOfVisibleItems = this.getCalculatedItemsToShow();
211217
const childHeight = height / children.length;
212218
nextState.rootHeight = childHeight * numOfVisibleItems;
213219
nextState.childHeight = childHeight;
@@ -225,7 +231,7 @@ class Carousel extends React.Component {
225231
/* based on slider container's width, get num of items to show
226232
* and calculate child's width (and update it in state)
227233
*/
228-
const visibleItems = this.getNumOfVisibleItems();
234+
const visibleItems = this.getCalculatedItemsToShow();
229235
const childWidth = verticalMode ? width : width / visibleItems;
230236
this.setState(
231237
state => ({ childWidth }),
@@ -269,7 +275,7 @@ class Carousel extends React.Component {
269275
getNextItemIndex = (currentIndex, getPrev) => {
270276
const { children } = this.props;
271277
const itemsToScroll = this.getItemsToScroll();
272-
const numOfvisibleItems = this.getNumOfVisibleItems();
278+
const numOfvisibleItems = this.getCalculatedItemsToShow();
273279
const notEnoughItemsToshow = numOfvisibleItems > children.length;
274280
let limit = getPrev ? 0 : children.length - numOfvisibleItems;
275281

@@ -383,7 +389,7 @@ class Carousel extends React.Component {
383389
const { firstItem } = this.state;
384390
const isPrev = firstItem > nextItemId;
385391
const nextAvailbaleItem = this.getNextItemIndex(firstItem, isPrev);
386-
const itemsToshow = this.getNumOfVisibleItems();
392+
const itemsToshow = this.getCalculatedItemsToShow();
387393
const noChange = nextAvailbaleItem === firstItem;
388394
const outOfBoundry = nextItemId + itemsToshow >= children.length;
389395
if (noChange) {
@@ -424,15 +430,15 @@ class Carousel extends React.Component {
424430

425431
getNumOfPages = () => {
426432
const { children } = this.props;
427-
const numOfVisibleItems = this.getNumOfVisibleItems();
433+
const numOfVisibleItems = this.getCalculatedItemsToShow();
428434
const numOfPages = Math.ceil(children.length / numOfVisibleItems);
429435
return numOfPages || 1;
430436
};
431437

432438
updateActivePage = () => {
433439
this.setState(state => {
434440
const { firstItem, activePage } = state;
435-
const numOfVisibleItems = this.getNumOfVisibleItems();
441+
const numOfVisibleItems = this.getCalculatedItemsToShow();
436442
const newActivePage = Math.ceil(firstItem / numOfVisibleItems);
437443
if (activePage !== newActivePage) {
438444
return { activePage: newActivePage };
@@ -441,7 +447,7 @@ class Carousel extends React.Component {
441447
};
442448

443449
onIndicatorClick = indicatorId => {
444-
const numOfVisibleItems = this.getNumOfVisibleItems();
450+
const numOfVisibleItems = this.getCalculatedItemsToShow();
445451
const gotoIndex = indicatorId * numOfVisibleItems;
446452
this.setState({ activePage: indicatorId });
447453
this.goTo(gotoIndex);
@@ -545,7 +551,7 @@ class Carousel extends React.Component {
545551
children={children}
546552
childWidth={childWidth}
547553
currentItem={firstItem}
548-
itemsToShow={itemsToShow}
554+
itemsToShow={this.getCalculatedItemsToShow()}
549555
itemPosition={itemPosition}
550556
itemPadding={itemPadding}
551557
enableSwipe={enableSwipe}

0 commit comments

Comments
 (0)