13
13
14
14
<script setup lang="ts">
15
15
// import type {BTabProps} from '../../types/components'
16
- import type { Booleanish , ClassValue } from ' ../../types '
16
+ import { computed , inject , ref , toRef , watch } from ' vue '
17
17
import {useBooleanish } from ' ../../composables'
18
- import { computed , inject , toRef } from ' vue '
18
+ import type { Booleanish , ClassValue } from ' ../../types '
19
19
import {injectionKey } from ' ./BTabs.vue'
20
20
21
21
interface BTabProps {
@@ -25,6 +25,7 @@ interface BTabProps {
25
25
buttonId? : string
26
26
disabled? : Booleanish
27
27
lazy? : Booleanish
28
+ lazyOnce? : Booleanish
28
29
noBody? : boolean | string
29
30
tag? : string
30
31
titleItemClass? : ClassValue
@@ -36,27 +37,43 @@ const props = withDefaults(defineProps<BTabProps>(), {
36
37
active: false ,
37
38
buttonId: undefined ,
38
39
disabled: false ,
39
- lazy: false ,
40
+ lazy: undefined ,
41
+ lazyOnce: undefined ,
40
42
noBody: false ,
41
43
tag: ' div' ,
42
44
titleItemClass: undefined ,
43
45
titleLinkAttributes: undefined ,
44
46
titleLinkClass: undefined ,
45
47
})
46
48
49
+ const lazyRenderCompleted = ref (false )
50
+
47
51
const activeBoolean = useBooleanish (toRef (props , ' active' ))
48
52
const disabledBoolean = useBooleanish (toRef (props , ' disabled' ))
49
- const lazyBoolean = useBooleanish (toRef (props , ' lazy' ))
53
+ const lazyBoolean = useBooleanish (toRef (props , props . lazyOnce !== undefined ? ' lazyOnce ' : ' lazy' ))
50
54
51
55
const parentData = inject (injectionKey , null )
52
56
53
57
const computedLazy = computed <boolean >(() => parentData ?.lazy || lazyBoolean .value )
58
+ const computedLazyOnce = computed <boolean >(() => props .lazyOnce !== undefined )
59
+
54
60
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
+ })
56
66
57
67
const classes = computed (() => ({
58
68
' active' : activeBoolean .value ,
59
69
' show' : activeBoolean .value ,
60
70
' card-body' : parentData ?.card && props .noBody === false ,
61
71
}))
72
+
73
+ watch (
74
+ () => showSlot .value ,
75
+ (shown ) => {
76
+ if (shown && ! lazyRenderCompleted .value ) lazyRenderCompleted .value = true
77
+ }
78
+ )
62
79
</script >
0 commit comments