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

Prevent Tab link to add active class to Parent li #15186

Closed
moinakbarali opened this issue Nov 20, 2014 · 6 comments
Closed

Prevent Tab link to add active class to Parent li #15186

moinakbarali opened this issue Nov 20, 2014 · 6 comments
Labels

Comments

@moinakbarali
Copy link

When I click on a link which has data-toggle="tab" inside li it automatically add active class to parent li.

Is there a way I can prevent bootstrap tabs link to add active class to current parent li because I want to do it manually?

@juthilo juthilo added the js label Nov 20, 2014
@peterblazejewicz
Copy link
Contributor

@moinakbarali

$('.nav-tabs').on('show.bs.tab', 'a', function(event) {
    event.preventDefault();
});
$('.nav-tabs').on('hide.bs.tab', 'a', function(event) {
    event.preventDefault();
});

Above (any of above handlers) stops plugin internal routine from managing previous/current active state selection after clicking a tab:
https://github.com/twbs/bootstrap/blob/master/js/tab.js#L47
So it's up to you to implement the rest

@moinakbarali
Copy link
Author

@peterblazejewicz
I solved it, On 'shown.bs.tab' I removed active class from all li.
But I think it should not be the default behavior of Bootstrap tabs. there should be an option to enable or disable this like collapse plugin use data-parent.

@redbmk
Copy link
Contributor

redbmk commented Dec 2, 2014

Does the li being given the active class have the .dropdown class? If so, I believe this is due to a bug I just ran into:
https://github.com/twbs/bootstrap/blob/master/js/tab.js#L91

The code essentially says if (true) since element.parent('.dropdown-menu') will always return an Array, which will evaluate to true. I think the code should be changed to element.parent('.dropdown-menu').length. If that's not your problem please let me know so I can file a bug elsewhere.

@mdo
Copy link
Member

mdo commented Jan 18, 2015

I don't think we'll be adding anything to the project to do this. Thanks though.

@mdo mdo closed this as completed Jan 18, 2015
@redbmk
Copy link
Contributor

redbmk commented Jan 19, 2015

@mdo, Does this line in tab.js not seem like it is unintentionally always adding the active class to the dropdown? An example would be if you had tabs nested inside a dropdown. It seems like a bug and this one-line fix might solve @moinakbarali's issue:

-      if (element.parent('.dropdown-menu')) {
+      if (element.parent('.dropdown-menu').length) {

@cvrebert
Copy link
Collaborator

Yeah, that's definitely a bug. Opened #15630.

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

No branches or pull requests

6 participants