All files / src/utils moveFocus.js

92.31% Statements 12/13
55.56% Branches 5/9
100% Functions 4/4
90% Lines 9/10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 204x 3x 3x     3x 3x     2x 2x   2x 2x            
const getHandleFocusMethod = calcIndex => (itemsAndActiveIndex = {}) => {
  const { children, activeIndex } = itemsAndActiveIndex;
  Iif (children.length === 0) {
    return;
  }
  const index = calcIndex(activeIndex, children);
  children[index] && children[index].focus();
};
 
const calcNextIndex = (activeIndex, children) => (activeIndex === children.length - 1 ? 0 : activeIndex + 1);
const calcPreviousIndex = (activeIndex, children) => (activeIndex === 0 ? children.length - 1 : activeIndex - 1);
 
const focusNextItem = getHandleFocusMethod(calcNextIndex);
const focusPreviousItem = getHandleFocusMethod(calcPreviousIndex);
 
export {
  focusNextItem,
  focusPreviousItem
};