[b-tabs] Cannot dynamically switch to a newly pushed b-tab by b-tabs v-model
See original GitHub issueDescribe the bug
Cannot dynamically switch to a newly pushed b-tab by b-tabs v-model.
Steps to reproduce the bug
- Have a b-tabs with v-model tabIndex binding
- Render b-tab in a v-for loop from an array
- Have a b-button that dynamically push a new tab to that array and switch to the last tab
Example code
<div id="app">
<div>
<b-tabs v-model="tabIndex">
<b-tab v-for="i in tabArr" :key="i" :title="i"></b-tab>
</b-tabs>
<b-button @click="newTab">New tab</b-button>
</div>
</div>
window.onload = () => {
new Vue({
el: '#app',
data() {
return {
tabIndex: -1,
tabArr : [-1]
}
},
watch: {
tabIndex(){
console.log(this.tabIndex)
}
},
methods: {
newTab() {
this.tabArr.push(this.tabArr.length)
this.$nextTick(()=>{this.tabIndex = this.tabArr.length - 1})
}
}
})
}
Expected behaviour
On a button click the new tab is added, the tab then immediately becomes active.
Actual behaviour
The tab that is next to the currently active becomes active. Jitter in the tabIndex value (can be seen by watching for tabIndex).
Versions
- BootstrapVue: 2.0.0-rc.24
- Vue: 2.6.10
Environment: not relevant
Demo link
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Tabs | Components
Create a widget of tabbable panes of local content. The tabs component is built upon navs and cards internally, and provides full keyboard...
Read more >How can I display immediately the new opened tab ...
Use b-tabs. Event: changed; Property: v-model. <b-tabs v-model="tabActive" @changed="onTabChanged"> data() { return { tabActive: 0, tabs:[], } ...
Read more >BootstrapVue — Dynamic Tabs and Time Pickers
We can make tabs dynamic by rendering b-tab with v-for . Also, BootstrapVue comes with a time picker that we can let the...
Read more >Dynamically add v-tab-item while maintaining animation order ...
Coding example for the question Dynamically add v-tab-item while maintaining animation ... You can not change this behavior unless you patch Vuetify.
Read more >Vue Tabs open the correct tab on page load
I took a look and cant see how to get the url and compare it to the tab ... <b-tabs content-class="mt-3" v-model="myIndex" @input="change()">...
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
yeah… looked after I replied.
because of the update cycle that B-Tabs needs to do when detecting new tabs (and not to trigger an endless update loop), we use nextTicks and requestAnimationFrame (to handle the default transition timing).
Here is an example fiddle that works, using a double nextTick and RequestAnimationFrame:
https://jsfiddle.net/to0vL4wu/
What is happening is that b-tabs tries to respect previously active b-tab’s localAvtive state when new tabs are added (unless they are explicitly added with the
active
prop set)We will be introducing a
changed
event, which will be emitted whenever child tabs are added, removed, or re-ordered. It will fire off once the render/state update cycle has completed.