How to use the @leafygreen-ui/lib.keyMap.ArrowRight function in @leafygreen-ui/lib

To help you get started, we’ve selected a few @leafygreen-ui/lib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mongodb / leafygreen-ui / packages / tabs / src / Tabs.tsx View on Github external
function handleKeyDown(e: React.KeyboardEvent) {
    e.stopPropagation();

    const enabledIndexes = childrenArray.reduce((acc, child, index) => {
      if (child.props.disabled) {
        return acc;
      }

      return [...acc, index];
    }, [] as Array);

    const enabledCurrentIndex = enabledIndexes.indexOf(selected!);

    switch (e.keyCode) {
      case keyMap.ArrowRight:
        setSelected(
          enabledIndexes[(enabledCurrentIndex + 1) % enabledIndexes.length],
        );
        break;

      case keyMap.ArrowLeft:
        setSelected(
          enabledIndexes[
            (enabledCurrentIndex - 1 + enabledIndexes.length) %
              enabledIndexes.length
          ],
        );
        break;
    }
  }