b-v-toggle does not appear to work with a click handler
See original GitHub issueDescribe the bug
A clear and concise description of what the bug is.
Steps to reproduce the bug
We have a link that shows a b-collapse element like this:
<b-card-header header-tag="header" role="tab">
<a v-b-toggle="'week-' + i" href="#" @click="getDefaults">{{week.dates.join(' - ')}}</a>
</b-card-header>
<b-collapse :id="'week-' + i" accordion="weeks" role="tabpanel" @show="getDefaults">
Toggling visibility of the b-collapse element doesn’t work unless we remove the @click directive (or set it to have no handler, like in the examples.)
Expected behavior
Clicking the link should show/hide the b-collapse element, even with an @click handler.
Versions
Libraries:
- BootstrapVue: 2.15.0
- Bootstrap: 4.5.0
- Vue: 2.6.11
Environment:
- OS: Linux
- Browser: Firefox
- Version: 76.0.1
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:6 (3 by maintainers)
Top Results From Across the Web
jQuery Toggle onClick Function not working as expected
I would set the click event handler only on your h4 element. var element = $('.myElement') element.find("h4").click(function () { element.
Read more >Handling Events - React
React events are named using camelCase, rather than lowercase. With JSX you pass a function as the event handler, rather than a string....
Read more >Introduction to browser events - The Modern JavaScript Tutorial
An event is a signal that something has happened. All DOM nodes generate such signals (but events are not limited to DOM).
Read more >JavaScript - Bootstrap
All dropdown events have a relatedTarget property, whose value is the toggling anchor element. Event Type, Description. show.bs.dropdown, This event fires ...
Read more >.toggle() | jQuery API Documentation
Use true to show the element or false to hide it. Note: The event handling suite also has a method named .toggle(). Which...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Okay.
So i played around with your jsfiddle. The reason you couldn’t reproduce it was because you forgot to add
this.
infront of your variables in the method.After playing around with it, it seems to be that if you assign a value to a data property that’s present in the template, the collapse will no longer open. You can access them fine and use them. But any assignment will cancel out the collapse.
This appears to be a problem in version
v2.14.0
and above.So a temporary workaround would be to rollback to version
v.2.13.0
where it should work as intended.Reproduction of the issue with some comments: https://codepen.io/Hiws/pen/MWKbxYp
You can use the
v-model
onb-collapse
orb-sidebar
, to get the current state of the component. This way you don’t have to manually toggle the property (i’m guessing), you were toggling in the click event.Another way would be to do as Mangyvr and use a single method to update the lable and run
this.$root.$emit('bv::toggle::collapse', 'my-collapse-id')
.