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

Add highlighting for standard links and dropdown #1414

Merged
merged 3 commits into from
Dec 11, 2020

Conversation

jonahtanjz
Copy link
Contributor

@jonahtanjz jonahtanjz commented Dec 10, 2020

What is the purpose of this pull request?

  • Documentation update
  • Bug fix
  • Feature addition or enhancement
  • Code maintenance
  • Others, please explain:

Overview of changes:
Fixes #1390. This adds highlighting to individual links/anchortags, as well as individual dropdown items. For anchortags, if window.location.href matches its a.href, it will be assigned the current class. For dropdowns, the parent (dropdown header) will be assigned the current class and the child (dropdown item) will be assigned the dropdown-current class which will highlight both the parent and child links.

Anything you'd like to highlight / discuss:
Implementation and code quality

Testing instructions:

  1. Create a navbar with dropdown and standard links
  2. Click on each link
  3. The link that the page is currently on will be highlighted

Proposed commit message: (wrap lines at 72 characters)
Extend navbar highlighting to standard links and dropdowns


Checklist: ☑️

  • Updated the documentation for feature additions and enhancements
  • Added tests for bug fixes or features
  • Linked all related issues
  • No blatantly unrelated changes
  • Pinged someone for a review!

@jonahtanjz jonahtanjz marked this pull request as draft December 10, 2020 08:12
Copy link
Contributor

@ang-zeyu ang-zeyu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! @jonahtanjz Really clean implementation

Some comments, and one open question:

@@ -132,9 +132,10 @@
const navLis = Array.from(this.$el.querySelector('.navbar-nav').children);
// attempt an exact match first
for (const li of navLis) {
const standardLinks = [li];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm what's this for? 😮

tried removing this and it worked fine still

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh this is for cases where the navbar does not use the li tags.
For example:

<header>
  <navbar type="dark">
    <a slot="brand" href="{{baseUrl}}/index.html" title="Home" class="navbar-brand">Your Logo</a>
    <a href="{{baseUrl}}/contents/topic1.html" class="nav-link">Topic 1</a>
    <a href="{{baseUrl}}/contents/topic2.html" class="nav-link">Topic 2</a>
    <a href="{{baseUrl}}/contents/topic3a.html" class="nav-link">Topic 3a</a>
    <a href="{{baseUrl}}/contents/topic3b.html" class="nav-link">Topic 3b</a>
  </navbar>
</header>

In this case, without this line, the highlighting would not work properly as navLinks only looks for anchortags within li.
I'm not sure if the above navbar example is valid as each item is not within a li tag. If it is not supposed to be valid, then this line, const standardLinks = [li];, is not needed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the explanation; nice catch 👍

@@ -160,16 +165,25 @@
if (hlMode === 'sibling-or-child') {
if (this.isSibling(url, a.href) || this.isChild(url, a.href)) {
li.classList.add('current');
if (dropdownLinks.includes(a)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's move L167-170 to a inner function and use that - less repitition

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright thanks. I have shifted this to an inner function.

@@ -463,3 +463,8 @@ button.copy-btn {
.navbar.navbar-dark.bg-primary .navbar-nav .current {
background: rgba(255, 255, 255, 0.05);
}

.dropdown-current {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could use vue loader's deep selectors here to encapsulate it in navbar.vue

https://vue-loader.vuejs.org/guide/scoped-css.html

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have moved this block into navbar.vue. Thanks.

@jonahtanjz
Copy link
Contributor Author

Thanks for the review @ang-zeyu. One question, I've also written additional test site but when I ran npm run updatetest, alot of other test files got modified in the process. Not sure if this is intended or I'm not doing it correctly.

@ang-zeyu
Copy link
Contributor

Thanks for the review @ang-zeyu. One question, I've also written additional test site but when I ran npm run updatetest, alot of other test files got modified in the process. Not sure if this is intended or I'm not doing it correctly.

This (ideally) needs vue snapshot tests (which tests post-vue-render diffs), not our custom functional tests which we mostly use to detect unwanted changes on the backend (automatically, without serving them up)

Vue snapshot tests were added rather recently in MarkBind/vue-strap#146 though, and only for <box>es. We don't have a whole lot of them yet.

I'm ok with proceeding without tests for now, we could add them for navbars (and etc.) in a later PR together. 🙂

Copy link
Contributor

@ang-zeyu ang-zeyu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm, are you intending to make anymore changes? (seeing that this is a draft)

@jonahtanjz jonahtanjz marked this pull request as ready for review December 11, 2020 17:22
@jonahtanjz
Copy link
Contributor Author

Thanks @ang-zeyu for the clarification. Nope I don't intend to make anymore changes and I have opened the PR now.

@ang-zeyu ang-zeyu added this to the v3.0 milestone Dec 11, 2020
@ang-zeyu ang-zeyu merged commit dc9267c into MarkBind:master Dec 11, 2020
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

Successfully merging this pull request may close these issues.

Extend navbar highlighting to <a> tags and dropdowns
2 participants