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 '
1717import {useBooleanish } from ' ../../composables'
18- import { computed , inject , toRef } from ' vue '
18+ import type { Booleanish , ClassValue } from ' ../../types '
1919import {injectionKey } from ' ./BTabs.vue'
2020
2121interface 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+
4751const activeBoolean = useBooleanish (toRef (props , ' active' ))
4852const disabledBoolean = useBooleanish (toRef (props , ' disabled' ))
49- const lazyBoolean = useBooleanish (toRef (props , ' lazy' ))
53+ const lazyBoolean = useBooleanish (toRef (props , props . lazyOnce !== undefined ? ' lazyOnce ' : ' lazy' ))
5054
5155const parentData = inject (injectionKey , null )
5256
5357const computedLazy = computed <boolean >(() => parentData ?.lazy || lazyBoolean .value )
58+ const computedLazyOnce = computed <boolean >(() => props .lazyOnce !== undefined )
59+
5460const 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
5767const 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