Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NavigationDrawer selected logic is wrong #7

Open
tv42 opened this issue Aug 8, 2020 · 0 comments
Open

NavigationDrawer selected logic is wrong #7

tv42 opened this issue Aug 8, 2020 · 0 comments

Comments

@tv42
Copy link

tv42 commented Aug 8, 2020

          <ListItem
            selected={path.includes(item.to)}

<ListItem
selected={path.includes(item.to)}

That triggers whenever the current URL path happens to contain the destination.
For example, if you add a new src/routes/aboutfoo.svelte that'll set "About" as active.

I did this, instead:

              selected={isActive(path, item.to)}
 function isActive(path, to) {
     if (to == path) {
         return true
     }
     if (path.startsWith(to+"/")) {
         return true
     }
     return false
 }

The second if marks an item selected if the current URL is below. Whether one wants that or not depends on whether the NavigationDrawer contains just one level, or multiple. Highlighting only the most exact matching entry gets a little tricky...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant