question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

b-nav-item-dropdown active state

See original GitHub issue

In Bootstrap NavBar, an active class can be set on the a tag which is a direct sibling of the li tag in order to mark the dropdown as active (indicating that any of its sibling pages is currently in view). See image below

image

Notice the Lang dropdown? The rendered markup is provided below

<li class="nav-item b-nav-dropdown dropdown">
  <a
    href="#"
    aria-haspopup="true"
    aria-expanded="false"
    class="nav-link dropdown-toggle active"
  >
    <span>Lang</span>
  </a>
  <div
    tabindex="-1"
    class="dropdown-menu dropdown-menu-right"
    aria-labelledby="__BVID__212__BV_button_"
  >
    <a role="menuitem" target="_self" href="#" class="dropdown-item">EN</a>
    <a role="menuitem" target="_self" href="#" class="dropdown-item">ES</a>
    <a role="menuitem" target="_self" href="#" class="dropdown-item">RU</a>
    <a role="menuitem" target="_self" href="#" class="dropdown-item">FA</a>
  </div>
</li>

How can this same behaviour be replicated using Bootstrap-Vue? Because I don’t see this anywhere in the docs.

<b-nav-item-dropdown text="Profile" right>
  <b-dropdown-item :to="{ name: 'Timeline' }">
    Timeline
  </b-dropdown-item>
  <b-dropdown-item :to="{ name: 'Edit' }">Edit</b-dropdown-item>
</b-nav-item-dropdown>

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
MoonCheungcommented, Oct 3, 2019

🙂 :extra-toggle-classes was scrapped, now :toggle-class is props instead of implementing ternary expressions

1reaction
simioluwatomicommented, Mar 20, 2019

Thanks for your quick response. For future reference, this was what worked for me

:extra-toggle-classes="$route.name === 'foobar' ? 'active' : ''"

This [extra-toggle-classes="$route.name === 'foobar' ? 'active' : '"] applied all the text as a class attribute.

But then, if more b-dropdown-items are added, this would become unwieldy as I would need to check for each route name. Is there a way to have an inclusive match that would apply the active class for any route under that dropdown? I set-up the routes like so /b-nav-item-dropdown/b-dropdown-item.

Once again, thanks for your time.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nav | Components - BootstrapVue
Navigation components that share general markup and styles, from the base class to the active and disabled states. Swap modifier props to switch...
Read more >
Bootstrap navbar Active State not working - Stack Overflow
I use the class="active" on my navbar and it does not switch when I press menu items. I know how to do this...
Read more >
Navs - Bootstrap
Base nav. Navigation available in Bootstrap share general markup and styles, from the base .nav class to the active and disabled states. Swap...
Read more >
how to highlight active nav-item? - Material Design for Bootstrap
The routerLinkActive directive should update the active state of the element also when you click on a specific link. You can use (click)...
Read more >
Bootstrap dropdowns - CoreUI
Opt into darker dropdowns to match a dark navbar or custom style by adding ... Add .active to items in the dropdown to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found