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-tab> Extending component causes b-tab to stop working

See original GitHub issue

Heya,

I am trying to create a custom tab component to incorporate extra components and reduce duplicate code.

Sadly, whenever I try to use extends or mixins with the tab component, the tab navigation stops working.

Steps to reproduce the bug

  1. Create a custom component:
<template>
  <b-tab v-bind="$props">
    <slot></slot>
    <pagination v-if="pagination"
                :total-rows="pagination.totalRows"
                :per-page="pagination.limit">
    </pagination>
  </b-tab>
</template>

<script>
import Tab from 'bootstrap-vue/es/components/tabs/tab';
import Pagination from '@/components/Pagination.vue';

export default {
  name: 'Tab',
  extends: Tab,
  components: {
    Pagination,
  },
  props: {
    ...Tab.props,
    pagination: false
  }
}
</script>
  1. Create a component that incorporates our element within a <b-tabs> element.
  2. Click on the tab header
  3. No tab-content is visible

Expected behavior

That the tab works just like a normal tab and makes the correct tab-content visible.

Versions

Libraries:

  • BootstrapVue: 2.0.0-rc.19
  • Bootstrap: 4.3.1
  • Vue: 2.6.10

Environment:

  • OS: Any (Fedora, Mac OS, Windows)
  • Browser: Chrome
  • Version: Chrome 74.0.3729.131

Additional context

I have used the example of the b-button from here

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
tmorehousecommented, Jun 14, 2019

@Pidz-b Version 2.0.0-rc.23 has been released.

0reactions
tmorehousecommented, Jun 4, 2019

@Pidz-b Here is a solution that may work, although the detection routine that scans the DOM after mount for tabs tries to get the b-tab instances from the element reference (i.e. el.__vue__), so thre is a chance it may not detect the b-tab instances after mount (since you are adding an extra layer in the component parent stack)

<template>
  <b-tab v-bind="$props" v-on="$listeners">
    <!-- this will pass the title slot to the b-tab instance, if provided -->
    <template v-if="$slots.title" slot="title"><slot name="title"></slot></template>
    <!-- default tab content -->
    <slot></slot>
    <!-- optional custom pagination component -->
    <pagination v-if="pagination"
                :total-rows="pagination.totalRows"
                :per-page="pagination.limit">
    </pagination>
  </b-tab>
</template>

<script>
import BTab from 'bootstrap-vue';
import Pagination from '@/components/Pagination.vue';

export default {
  name: 'Tab',
  components: {
    BTab,
    Pagination,
  },
  props: {
    // Add in all of BTab's props
    ...BTab.props, // or maybe ...BTab.$options.props,
    // Add in new prop
    pagination: false
  }
}
</script>

This might be close, but we may need to alter the detection routine a bit to handle the case of the tab being nested inside another component.

EDIT: the new updated tab detection routine in PR #3442 should make this example work

The problem with extending BTab would be the registration of the child tab’s with the parent b-tabs component, as having a child b-tab in your render would make two tabs get registered (your extended b-tab and the nested b-tab, the latter being the one that needs to be registered with b-tabs). You would need to override the injection in your extended component options:

<template>
  <b-tab v-bind="$props" v-on="$listeners">
    <template v-if="$slots.title" slot="title"><slot name="title"></slot></template>
    <slot></slot>
    <pagination v-if="pagination"
                :total-rows="pagination.totalRows"
                :per-page="pagination.limit">
    </pagination>
  </b-tab>
</template>
<script>
import BTab from 'bootstrap-vue'
import Pagination from '@/components/pagination'

export default {
  name: 'MyTab',
  extends: BTab,
  inject: {
    // Override `bvTabs` injection, returning an empty object
    bvTabs: {
      from: 'NothingToSeeHere', // fake source to override injection
      default() { return {} }
    }
  },
  components: {
    BTab,
    pagination
  },
  props: {
    pagination: {
      type: Boolean,
      default: false
    }
  }
}
</script>

EDIT 2: With a minor tweak in the b-tabs child b-tab detection routine, the above inject override is no longer needed (but wont hurt).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tabs | Components - BootstrapVue
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 >
aura - Extending Lightning Components not working
It can have different values at each level of component extension to enable different output from each component in the inheritance chain.
Read more >
The MUMmer 3 manual - SourceForge
Using a seed and extend strategy, other parts of the MUMmer pipeline use these exact matches as alignment anchors to generate pair-wise alignments...
Read more >
DoD Instruction 1010.16, Technical Procedures for the Military ...
(3) Biochemical Testing Advisory Board (BTAB). ... measures to maximize the use of facilities and equipment by expanding work schedules and.
Read more >
Analog TDS Sensor - DFRobot WIKI
The probe can not be used in water above 55 degrees centigrade. ... int iFilterLen) { int bTab[iFilterLen]; for (byte i = 0;...
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