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

feat: Added support for navigation menu dropdown #344

Merged
merged 4 commits into from
Apr 23, 2022

Conversation

guidemetothemoon
Copy link
Contributor

@guidemetothemoon guidemetothemoon commented Apr 10, 2022

Description

Describe the issue fixed here

I've had a need to create a dropdown navigation menu section and I hope that support for this in standard Anatole theme might be useful for others. This is an option you can implement when you need it and I've used the same style as the one that was implemented for language dropdown. In order to ensure naming consistency, I've renamed all "language*" SCSS classes to use a more generic name: "optionswitch*".
Implementation follows standard support for section dropdown implementation in Hugo, i.e. the user can define subsections in "menus.*.toml" file by adding a "parent" property, like I've demonstrated in exampleSite:
`
[[main]]
name = "Accomplishments"
weight = 500
identifier = "accomplishments"

[[main]]
name = "Awards"
weight = 510
identifier = "awards"
url = "/awards/"
parent = "accomplishments"

[[main]]
name = "Certifications"
weight = 520
identifier = "certifications"
url = "/certifications/"
parent = "accomplishments"
`
The dropdown will then look like this:

image

Here, Accomplishments is a parent menu option which is not a page in itself but Awards and Certifications are it's children which are pages representing different content. By providing weight parameter I can define in what order menu options will be displayed in the dropdown.

I've added an example of the implementation in the exampleSite. Since documentation is in GitHub Wiki and this PR hasn't been merged yet, I haven't added any additional documentation apart from the description in this PR. But please let me know if I need to add that.

Also, I've updated class names for language dropdown in navbar.html accordingly to use the new naming.
Finally I've excluded *.min.css Fontawesome files from prettier formatting because every time it's run, the checksum for the files will change due to added indentation and minified files should stay compressed. Seems like in the latest merged changeset those files got modified by the prettier extension again but those got modified back as part of this PR.

Issue Number:

  • Here Goes the Issue Number with a '#'

Additional Information (Optional)

  • Here goes any Additional Information you would like to add.

Checklist

Yes, I included all necessary artefacts, including:

  • Tests
  • Documentation
  • Implementation (Code and Ressources)
  • Example

Testing Checklist

Yes, I ensured that all of the following scenarios were tested:

  • Desktop Light Mode (Default)
  • Desktop Dark Mode
  • Desktop Light RTL Mode
  • Desktop Dark RTL Mode
  • Mobile Light Mode
  • Mobile Dark Mode
  • Mobile Light RTL Mode
  • Mobile Dark RTL Mode

Notify the following users

  • List users with @ to send Notifications
    @lxndrblz

@netlify
Copy link

netlify bot commented Apr 10, 2022

Deploy Preview for anatole-demo ready!

Name Link
🔨 Latest commit a21f58c
🔍 Latest deploy log https://app.netlify.com/sites/anatole-demo/deploys/6263b2f1ab345d0009c1eb35
😎 Deploy Preview https://deploy-preview-344--anatole-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@guidemetothemoon guidemetothemoon marked this pull request as ready for review April 10, 2022 13:56
@lxndrblz
Copy link
Owner

@guidemetothemoon Thanks for the PR. I will review it in the upcoming days.

@lxndrblz lxndrblz self-assigned this Apr 18, 2022
@lxndrblz lxndrblz added the enhancement New feature or request label Apr 18, 2022
@sonarcloud
Copy link

sonarcloud bot commented Apr 23, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@lxndrblz lxndrblz merged commit 6c55d42 into lxndrblz:master Apr 23, 2022
@guidemetothemoon
Copy link
Contributor Author

guidemetothemoon commented Apr 23, 2022

UPDATE: I found how to resolve the issue I'm mentioning below and will shortly publish a PR to fix it!

@lxndrblz thank you so much for your review and apologize for the late reply on your suggested changes! I got swamped with work this week and wasn't able to follow it up until this weekend. Suggested change is a bit more tricky though, I think that adding else-clause will not be enough, because the active CSS will not be applied if you choose menu option other than the first one in the dropdown. It looks like when you use "range" it only evaluates if the first option in the link is the one that currently is the active URL but if it's f.ex. option number 2 or 3 that's active, it'll not be evaluated towards if it's active or not. I tried to experiment with .IsMenuCurrent/.HasMenuCurrent but wasn't successful. I'm still new to development in Hugo so I'll use some time this weekend to investigate how you can check if current active URL belongs to any of the children, not only to the first one. I'll then publish a follow-up fix for that.
In case you know from the top of your head an easy way to search through all the children when doing active URL validation, please let me know :)

@guidemetothemoon guidemetothemoon deleted the feat/add-menu-dropdown branch April 24, 2022 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants