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

Collapse does not work when trigger element is label and transition is deactivated #17563

Closed
LaurentVB opened this issue Sep 10, 2015 · 2 comments
Labels

Comments

@LaurentVB
Copy link

Hello,

When deactivating the transitions, if the trigger element of the collapsing is a label containing a checkbox, and only if one clicks on the label text (not the checkbox), the element does not collapse.
From debugging, it looks like toggle is actually called twice, meaning the element is displayed and hidden immediately.

Tested in the latest chrome and firefox, with latest bootstrap 3.x and jquery 1.x
See http://jsbin.com/gosezuwama/1/edit?html,js,output for the repro.

Regards,

Laurent

@cvrebert
Copy link
Collaborator

This is just due to the inherent weirdness of click retargetting in HTML.
If you get rid of Bootstrap and just have a vanilla <label> and <input>, here's what happens when you click on the <label> text:

  • A click event (let's call it c1) is fired with its target being the <label>
  • Because clicking a <label> is supposed to be like clicking on its associated input, after c1 finishes propagating, the browser fires a new click event (let's call it c2) with the target this time being the <input>
  • c2 bubbles and is dispatched at the <label> because it's an ancestor of the <input>

Thus, two click events get dispatched to the <label>, and thus toggle gets called twice.
The solution is to put the data-toggle="collapse" data-target="#collapse-target" on the <input> instead of the <label>.

@LaurentVB
Copy link
Author

Thanks a lot for this very thorough explanation.

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

2 participants