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

Active navigation tab bug #150

Closed
EthanThatOneKid opened this issue Oct 14, 2021 · 2 comments
Closed

Active navigation tab bug #150

EthanThatOneKid opened this issue Oct 14, 2021 · 2 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@EthanThatOneKid
Copy link
Owner

EthanThatOneKid commented Oct 14, 2021

What happened?

The active page’s navigation tab does not stay active since the SvelteKit migration.

Original: #148

@EthanThatOneKid EthanThatOneKid added the bug Something isn't working label Oct 14, 2021
@EthanThatOneKid EthanThatOneKid added this to the v2.0 💫 milestone Oct 14, 2021
@dustinchavez1 dustinchavez1 self-assigned this Oct 23, 2021
@EthanThatOneKid
Copy link
Owner Author

Why I think this bug happened

So the reason that this bug has arisen is in Sapper, you can use a variable called segment to get the name of the current page's path. In SvelteKit, this variable has been removed (which is why our feature suddenly stopped working; segment was just always undefined).

What we can do about it

SvelteKit actually provides a module, $app/stores (https://kit.svelte.dev/docs#modules-$app-stores), which provides the data we need to determine if the page is currently active.

In navbar.svelte you can import the page store from $app/stores like so...

import { page } from '$app/stores';

Now that we are thinking of the menu items as paths (instead of slugs), we could then refactor the menuItems variable:

const menuItems = [
  { title: 'about', path: '/about' },
  { title: 'events', path: '/events' },
  { title: 'paths', path: '/paths' },
  {
    title: '<span class="headers">node</span>Buds',
    path: '/nodebuds',
  },
  { title: 'connect', path: '/connect' },
];

Finally, you can update the conditional statement that determines whether or not the aria-current HTML attribute is activated, which in turn activates the color. On line 40, update the conditional such that aria-current is true if $pages.path is equal to the path of the menuItem.

@EthanThatOneKid
Copy link
Owner Author

Closed by #163.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants