# All files / src/FileSelect/FileExplorer useSidebarNavigation.ts

94.44% Statements 17/18
83.33% Branches 5/6
100% Functions 3/3
94.44% Lines 17/18

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    505x

    5x
    48x
    48x

    48x

    48x

    2x

    2x

    2x
    1x

    1x

    48x

    5x

    5x
    2x

    3x

    48x

     import { useListNavigation } from '../../_hooks/ListNavigation'
    import {
      SidebarNavigationApi,
      SidebarNavigationConfig,
    } from './FileExplorer.types'

    export function useSidebarNavigation({
      selectedIndex,
      ...props
    }: SidebarNavigationConfig): SidebarNavigationApi {
      const listNavigation = useListNavigation({
        circular: true,
        ...props,
      })

      const up = () => {
        let shouldJumpOver: boolean

        Iif (listNavigation.index === 0) {
          shouldJumpOver = selectedIndex === listNavigation.size - 1
        } else {
          shouldJumpOver =
            (listNavigation.index - 1) % listNavigation.size === selectedIndex
        }

        if (shouldJumpOver) {
          listNavigation.decrementBy(2)
        } else {
          listNavigation.decrement()
        }
      }

      const down = () => {
        const shouldJumpOver =
          (listNavigation.index + 1) % listNavigation.size === selectedIndex

        if (shouldJumpOver) {
          listNavigation.incrementBy(2)
        } else {
          listNavigation.increment()
        }
      }

      return {
        ...listNavigation,
        up,
        down,
      }
    }