Skip to content

NavigationDrawer selected logic is wrong #7

@tv42

Description

@tv42
          <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...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions