Skip to content

Commit 5f4240b

Browse files
committed
feat(BTab): added new lazyOnce prop, The prop works similar to the lazy prop but it mounts the child component only once.
1 parent 8c5121d commit 5f4240b

File tree

1 file changed

+22
-5
lines changed
  • packages/bootstrap-vue-3/src/components/BTabs

1 file changed

+22
-5
lines changed

packages/bootstrap-vue-3/src/components/BTabs/BTab.vue

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414
<script setup lang="ts">
1515
// import type {BTabProps} from '../../types/components'
16-
import type {Booleanish, ClassValue} from '../../types'
16+
import {computed, inject, ref, toRef, watch} from 'vue'
1717
import {useBooleanish} from '../../composables'
18-
import {computed, inject, toRef} from 'vue'
18+
import type {Booleanish, ClassValue} from '../../types'
1919
import {injectionKey} from './BTabs.vue'
2020
2121
interface BTabProps {
@@ -25,6 +25,7 @@ interface BTabProps {
2525
buttonId?: string
2626
disabled?: Booleanish
2727
lazy?: Booleanish
28+
lazyOnce?: Booleanish
2829
noBody?: boolean | string
2930
tag?: string
3031
titleItemClass?: ClassValue
@@ -36,27 +37,43 @@ const props = withDefaults(defineProps<BTabProps>(), {
3637
active: false,
3738
buttonId: undefined,
3839
disabled: false,
39-
lazy: false,
40+
lazy: undefined,
41+
lazyOnce: undefined,
4042
noBody: false,
4143
tag: 'div',
4244
titleItemClass: undefined,
4345
titleLinkAttributes: undefined,
4446
titleLinkClass: undefined,
4547
})
4648
49+
const lazyRenderCompleted = ref(false)
50+
4751
const activeBoolean = useBooleanish(toRef(props, 'active'))
4852
const disabledBoolean = useBooleanish(toRef(props, 'disabled'))
49-
const lazyBoolean = useBooleanish(toRef(props, 'lazy'))
53+
const lazyBoolean = useBooleanish(toRef(props, props.lazyOnce !== undefined ? 'lazyOnce' : 'lazy'))
5054
5155
const parentData = inject(injectionKey, null)
5256
5357
const computedLazy = computed<boolean>(() => parentData?.lazy || lazyBoolean.value)
58+
const computedLazyOnce = computed<boolean>(() => props.lazyOnce !== undefined)
59+
5460
const computedActive = computed<boolean>(() => activeBoolean.value && !disabledBoolean.value)
55-
const showSlot = computed<boolean>(() => computedActive.value || !computedLazy.value)
61+
const showSlot = computed<boolean>(() => {
62+
const hasLazyRenderedOnce =
63+
computedLazy.value && computedLazyOnce.value && lazyRenderCompleted.value
64+
return computedActive.value || !computedLazy.value || hasLazyRenderedOnce
65+
})
5666
5767
const classes = computed(() => ({
5868
'active': activeBoolean.value,
5969
'show': activeBoolean.value,
6070
'card-body': parentData?.card && props.noBody === false,
6171
}))
72+
73+
watch(
74+
() => showSlot.value,
75+
(shown) => {
76+
if (shown && !lazyRenderCompleted.value) lazyRenderCompleted.value = true
77+
}
78+
)
6279
</script>

0 commit comments

Comments
 (0)