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

Dropdown items in nav tabs can get stuck in .active mode #17371

Closed
rebot opened this issue Aug 27, 2015 · 10 comments
Closed

Dropdown items in nav tabs can get stuck in .active mode #17371

rebot opened this issue Aug 27, 2015 · 10 comments

Comments

@rebot
Copy link

rebot commented Aug 27, 2015

bug bootstrap alpha v4 - http://v4-alpha.getbootstrap.com/components/navs/#javascript-behavior When you press a button/tab in the dropdown, try another tab and go back, you will see that the button/tab under the dropdown hasn't been deactivated. I was implementing this in a project and came across this bug.

EDIT: It's worse.. You can't even 'reactivate' the tab. So it's stuck on 'active' mode and won't change your content in the tab view

@crehard
Copy link

crehard commented Sep 4, 2015

screen shot 2015-09-04 at 15 10 56

@JoyceBabu
Copy link
Contributor

Until the code is fixed, the issue can be worked around by removing the active class from shown event

$('.nav-tabs').on('shown.bs.tab', 'a', function (e) {
    if (e.relatedTarget) {
        $(e.relatedTarget).removeClass('active');
    }
})

@mdo mdo modified the milestones: v4.0.0-alpha.2, v4.0.0-alpha.3 Dec 8, 2015
@JD-Robbs
Copy link

JD-Robbs commented Feb 7, 2016

Thanks for the workaround! 👍

@HallofFamer
Copy link

Any updates on this issue? Still not yet fixed? And Joyce Babu's workaround doesnt work for me at all...

@mdo mdo modified the milestones: v4.0.0-alpha.3, v4.0.0-alpha.4 May 8, 2016
@HallofFamer
Copy link

HallofFamer commented May 14, 2016

Note JoyceBabu's solution does not work unless you wrap it in $(document).ready(), like this:

$(document).ready(function() {
    $('.nav-tabs').on('shown.bs.tab', 'a', function(e) {
        console.log(e.relatedTarget);
        if (e.relatedTarget) {
            $(e.relatedTarget).removeClass('active');
        }
    });    
});

@JoyceBabu
Copy link
Contributor

@HallofFamer - Depends on where you place the code. It is almost always better to place the script tags at the end of the page, before the closing </html> tag. In that case, you don't need to wrap the code in $(document).ready or $() (unless it is a dynamic element created during dom ready).

@bpierson
Copy link

I was able to solve this with a combination of a workaround and changing the selector on line 2554.

Workaround:

$(document).ready(function () {
    $('.nav').on('shown.bs.tab', 'a', function (e) {
        console.log(e.relatedTarget);
        if (e.relatedTarget) {
            $(e.relatedTarget).removeClass('active in');
        }
    });
});

Selector change:

Old 2554: UL: 'ul:not(.dropdown-menu)',
New 2554: UL: 'ul:not(.dropdown-toggle), nav.nav:not(.dropdown-toggle)',

Without the selector change, the code is targeting the .dropdown with the .active class. You can see this in Chrome inspector by watching the .active class show up on the .dropdown element instead of the .dropdown-toggle element.

@mdo mdo modified the milestones: v4.0.0-alpha.5, v4.0.0-alpha.6 Oct 19, 2016
@mdo mdo closed this as completed in b1b1f30 Nov 25, 2016
@julien2404
Copy link

Hi,

I've the same issue but only for Multi-level dropdown.

       <li class="dropdown-submenu">
        <a class="test" href="#">APM QR Code Management-test<span class="caret"></span></a>
         <ul class="dropdown-menu">
              <li><a data-toggle="tab"  href="#APM">APM QR Code Management</a></li>
              <li><a data-toggle="tab" href="#IDENTITY">Identity Awareness Queries</a></li>
         </ul>
       </li>
<div class="tab-content"> 
<div id="APM" class="tab-pane fade">
<p> my content 1 </p>
</div>
</div>

<div class="tab-content"> 
<div id="IDENTITY" class="tab-pane fade">
<p> my content 2 </p>
</div>
</div>

In order to make the multi level work, I use JS :

$(document).ready(function(){
  $('.dropdown-submenu a.test').on("click", function(e){
    $(this).next('ul').toggle();
    e.stopPropagation();
    e.preventDefault();
  });
});

Here is the behavior

image

I do not meet the behavior with one layer dropdown.

Your help will be much appreciated :)

@Hasnatthecoder
Copy link

I have same issue i solve it using e.target
$(document).ready(function() {
$('.nav-tabs').on('shown.bs.tab', 'a', function(e) {
console.log(e.target);
if (e.target) {
$(e.target).removeClass('active');
}
});
});

2020-10-08

@rameshchokkara
Copy link

Help me to Fix This.
Screenshot (102)
SEM1 is Active.

It should also show that Engg2 is also Active.
Please Fix This.

Screenshot (103)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

12 participants