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

Fix - Navigation doesn't highlight current page #2

Closed
borntofrappe opened this issue Feb 15, 2022 · 3 comments
Closed

Fix - Navigation doesn't highlight current page #2

borntofrappe opened this issue Feb 15, 2022 · 3 comments
Assignees

Comments

@borntofrappe
Copy link
Owner

current-expected

@borntofrappe
Copy link
Owner Author

If you inspect the source the aria-current attribute wraps the string page between a superfluous set of quotes.

<a href="/" aria-current=""page"">Home</a>

@borntofrappe borntofrappe self-assigned this Feb 15, 2022
@borntofrappe
Copy link
Owner Author

It seems the issue stems from how the helper function injects the ARIA attribute, and the data-active attribute for that matters. You need to escape

<a
  href="{{item.url}}"
  {{helpers.getLinkActiveState(item.url, page.url)}}>
    {{item.text}}
</a>

You need to add the safe filter to avoid escaping the input.

{{helpers.getLinkActiveState(item.url, page.url)}}
+{{helpers.getLinkActiveState(item.url, page.url) | safe}}

@borntofrappe
Copy link
Owner Author

05246ee closes the issue.

Modifying the helper function would also work if you were to remove the quotes.

 response += ' aria-current="page"';
-response += ' aria-current=page';

I would discourage this approach however, as it creates confusion with how you expect HTML attributes to work. Relying on the safe filter clearly states that the output is to be treated as markup.

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