Skip to content

Commit

Permalink
🔨 Easier to understand tab selection
Browse files Browse the repository at this point in the history
  • Loading branch information
macdonst committed Nov 11, 2020
1 parent 6dc8605 commit dc6dc6b
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/Header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,13 @@ const Header = ({

const positionSelectedTabIndicator = () => {
const currentPath = location.pathname
const localTabs = tabRefs.filter(
(tab) => tab.current?.hostname === location.hostname
)

const selectedTab =
localTabs.find((tab) => {
return (
tab.current?.pathname !== withPrefix('/') &&
currentPath &&
currentPath.startsWith(tab.current?.pathname)
)
}) || localTabs[0]
tabRefs
.filter((tab) => currentPath.startsWith(tab.current?.pathname))
.sort(
(a, b) => b.current?.pathname.length - a.current?.pathname.length
)[0] || tabRefs[0]

positionIndicator(selectedTabIndicator, selectedTab)
}
Expand Down

0 comments on commit dc6dc6b

Please sign in to comment.