23
23
@keyup.esc =" onEsc"
24
24
>
25
25
<div class =" modal-dialog" :class =" modalDialogClasses" >
26
- <div class =" modal-content" :class =" contentClass" >
26
+ <div
27
+ v-if ="
28
+ !lazyBoolean ||
29
+ (lazyBoolean && lazyLoadCompleted) ||
30
+ (lazyBoolean && modelValueBoolean === true)
31
+ "
32
+ class =" modal-content"
33
+ :class =" contentClass"
34
+ >
27
35
<div v-if =" !hideHeaderBoolean" class =" modal-header" :class =" headerClasses" >
28
36
<slot name =" header" >
29
37
<component
99
107
100
108
<script setup lang="ts">
101
109
// import type {BModalEmits, BModalProps} from '../types/components'
102
- import {computed , ref , toRef , useSlots , watch } from ' vue'
110
+ import {computed , nextTick , ref , toRef , useSlots , watch } from ' vue'
103
111
import {useBooleanish , useId } from ' ../composables'
104
112
import type {Booleanish , ClassValue , ColorVariant , InputSize } from ' ../types'
105
113
import {isEmptySlot } from ' ../utils'
@@ -210,12 +218,10 @@ const emit = defineEmits<BModalEmits>()
210
218
211
219
const slots = useSlots ()
212
220
213
- const isActive = ref (false )
214
-
215
221
const computedId = useId (toRef (props , ' id' ), ' modal' )
216
222
217
223
const busyBoolean = useBooleanish (toRef (props , ' busy' ))
218
- // const lazyBoolean = useBooleanish(toRef(props, 'lazy'))
224
+ const lazyBoolean = useBooleanish (toRef (props , ' lazy' ))
219
225
const cancelDisabledBoolean = useBooleanish (toRef (props , ' cancelDisabled' ))
220
226
const centeredBoolean = useBooleanish (toRef (props , ' centered' ))
221
227
const hideBackdropBoolean = useBooleanish (toRef (props , ' hideBackdrop' ))
@@ -233,7 +239,9 @@ const scrollableBoolean = useBooleanish(toRef(props, 'scrollable'))
233
239
const titleSrOnlyBoolean = useBooleanish (toRef (props , ' titleSrOnly' ))
234
240
const staticBoolean = useBooleanish (toRef (props , ' static' ))
235
241
242
+ const isActive = ref (false )
236
243
const element = ref <HTMLElement | null >(null )
244
+ const lazyLoadCompleted = ref (false )
237
245
238
246
const modalClasses = computed (() => [
239
247
props .modalClass ,
@@ -303,18 +311,24 @@ const onBeforeEnter = () => emit('show')
303
311
const onAfterEnter = () => {
304
312
isActive .value = true
305
313
emit (' shown' )
314
+ if (lazyBoolean .value === true ) lazyLoadCompleted .value = true
306
315
}
307
316
const onBeforeLeave = () => emit (' hide' )
308
317
const onLeave = () => {
309
318
isActive .value = false
310
319
}
311
- const onAfterLeave = () => emit (' hidden' )
320
+ const onAfterLeave = () => {
321
+ emit (' hidden' )
322
+ if (lazyBoolean .value === true ) lazyLoadCompleted .value = false
323
+ }
312
324
313
325
watch (
314
326
() => modelValueBoolean .value ,
315
327
(newValue ) => {
316
- if (newValue === true && ! noFocusBoolean .value && element .value !== null ) {
317
- element .value .focus ()
328
+ if (newValue === true && ! noFocusBoolean .value ) {
329
+ nextTick (() => {
330
+ if (element .value !== null ) element .value .focus ()
331
+ })
318
332
}
319
333
}
320
334
)
0 commit comments