Skip to content

Active menu in navbar doesn't highlight subsections / child pages #90

@h-enk

Description

@h-enk

Discussed in thuliteio/doks#1178

Originally posted by jollydodo January 16, 2024

Description

Minor change and not necessarily an issue/bug, but something that is normally different and would be a visual improvement. The navbar shows which section is active. This works fine, however, it does not take into account subsections. E.g. if I go to about and then 'about us', neither the parent nor the child have a highlighted element. This is also the case for blog posts for example. 'blog' only stays highlighted on the blog index and not on a single post.

On one of my previous websites I used the default Hugo method ".isMenuCurrent' to highlight the selected link. This method also supports ancestor/child pages out of the box with very simple code. I looked at the Doks implementation and this seems a bit more intricate.

Default Hugo approach:

{{ $currentPage := . }}
{{ range site.Menus.main }}
{{ if $currentPage.IsMenuCurrent .Menu . }}
{{ .Name }}
{{ else if $currentPage.HasMenuCurrent .Menu . }}
{{ .Name }}
{{ else }}
{{ .Name }}
{{ end }}
{{ end }}

Visualization

Scherm­afbeelding 2024-01-16 om 22 56 13

Picture of another Hugo site: stays highlighted even in a post that is part of 'portfolio' using default Hugo implementation. This tells the user that they are currently viewing an item that is part of 'portfolio'.

Doks: ( "open-inloop" is a child of "over")

Scherm­afbeelding 2024-01-16 om 22 56 35

Neither 'open-inloop' or 'over' is highlighted as active.

Preferred outcome:
Scherm­afbeelding 2024-01-16 om 22 56 43

This would make the appearance of the navbar more consistent, because it already works like this for the default 'docs' pages:
Scherm­afbeelding 2024-01-16 om 23 08 34

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions