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] not able to active a new tab added on fly

See original GitHub issue

Describe the bug

The problem was also indicated in this closed ticket https://github.com/bootstrap-vue/bootstrap-vue/issues/1378 but I suspect never was solved ( if it might be solved? ).

Basically after adding a new tab dynamically is not possible to activate this tab on fly.

I’m using v-model=“groups” what is a list of elements

I have tested with :

this.$nextTick(() => {
          this.tabIndex = this.groups.length - 1;
        });

and also with

Vue.nextTick().then(() => {
          this.tabIndex = this.groups.length - 1;
        });

Expected behavior

I success get it working with a timeout, but seems a not safe way for doing it:

setTimeout(() => {
          this.tabIndex = this.groups.length - 1;
        }, 400);

I would like to know if it is another version to get it running

Versions

Libraries:

  • BootstrapVue: 2.0.0-rc.24
  • Bootstrap: 4.3.1
  • Vue: 2.6.6

Environment:

  • Browser: Chrome
  • Version: 75.0.3770.100 (Build oficial) (64 bits)

Demo link

Here is an old sample of the issue what is not working as expected: http://jsfiddle.net/cihkem/3apaaz4n/1/

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
tmorehousecommented, Aug 11, 2019

@darkman97i I just remembered about another way you could know when the tab is ready to be activated. <b-tabs> emits the event changed when tabs are added, removed, or re-ordered. You could listen to that event and update the v-model then, and you would no longer need the $nextTicks and requestAnimation frame.

https://bootstrap-vue.js.org/docs/components/tabs#comp-ref-b-tabs-events

<b-tabs v-model="currentTab" @changed="updateCurrent">
  <b-tab v-for="tab in tabs"  :title="tab.title" :key="tab.id">
    {{ tab.content }}
  </b-tab>
</b-tabs>
export default {
  data() {
     tabs: [],
     currentTab: 1
  },
  methods: {
    // ...
    updateCurrent(currentTabs, previousTabs) {
      if (currentTabs.length > previousTabs.length) {
        this.currentTab = currentTabs.length - 1
      }
    }
  }
1reaction
tmorehousecommented, Aug 9, 2019

When you diagrammatically add a tab (i.e. with v-if, or similar), you can have the b-tab’s active prop set, which will activate the tab once it is discovered (assuming the new tab appears last)

And after reviewing the code, I think you need a double nextTick + Request animation frame to set the new active tab index (via the v-model), to get around the delays required by the tab probing/disovery process:

this.$nextTick(() => {
  this.$nextTick(() => {
    requestAnimationFrame(() => {
      this.tabIndex = this.groups.length - 1;
    })
  })
});

Or if using the promise version of $nextTick (with async support):

await this.$nextTick();
await this.$nextTick();
requestAnimationFrame(() => {
  this.tabIndex = this.groups.length - 1;
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Chrome extension not automatically activating on new tab
When I open a new tab, the extension won't activate until I click on it. ... password is added dynamically. it just won't...
Read more >
How can Chrome not automatically switch to new tab, when ...
1) select "open link in new background tab" from the context menu (second choice), 2) use middle-click on the link with your mouse;...
Read more >
Use tabs in Chrome - Computer - Google Support
On your computer, open Chrome Chrome . · Click New tab New tab . · Right-click a tab and then select Add to...
Read more >
Tab Activate
With Tab Activate, new tabs open immediately instead of in the background. To override Tab Activate and open a new tab in the...
Read more >
Why can't I open a new Tab with the "Plus" sign or "Command ...
If I want to open a New Tab, I either press "Command T" or select "New Tab" from the File menu, or click...
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