question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[b-tabs] Cannot dynamically switch to a newly pushed b-tab by b-tabs v-model

See original GitHub issue

Describe the bug

Cannot dynamically switch to a newly pushed b-tab by b-tabs v-model.

Steps to reproduce the bug

  1. Have a b-tabs with v-model tabIndex binding
  2. Render b-tab in a v-for loop from an array
  3. 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

https://jsfiddle.net/tinbtb/dy5Lrfvu/4/

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
tmorehousecommented, Jun 26, 2019

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)

0reactions
tmorehousecommented, Jun 27, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found