== 0 ? lastTab : tabs[index - 1])
    }

    function setSelectedToNextTab(currentTab) {
      const index = tabs.indexOf(currentTab)
      setSelectedTab(index === tabs.length - 1 ? firstTab : tabs[index + 1])
    }

    function onKeydown(event) {
      const target = event.currentTarget
      let flag = false

      switch (event.key) {
        case 'ArrowLeft':
          setSelectedToPreviousTab(target)
          flag = true
          break
        case 'ArrowRight':
          setSelectedToNextTab(targe