18
18
role =" dialog"
19
19
:aria-labelledby =" `${computedId}-label`"
20
20
:aria-describedby =" `${computedId}-body`"
21
- :style =" {display: 'block'}"
22
21
tabindex =" -1"
23
22
v-bind =" $attrs"
24
23
@keyup.esc =" onEsc"
25
24
>
26
25
<div class =" modal-dialog" :class =" modalDialogClasses" >
27
- <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
+ >
28
35
<div v-if =" !hideHeaderBoolean" class =" modal-header" :class =" headerClasses" >
29
36
<slot name =" header" >
30
37
<component
100
107
101
108
<script setup lang="ts">
102
109
// import type {BModalEmits, BModalProps} from '../types/components'
103
- import {computed , ref , toRef , useSlots , watch } from ' vue'
104
- import {isEmptySlot } from ' ../utils'
110
+ import {computed , nextTick , ref , toRef , useSlots , watch } from ' vue'
105
111
import {useBooleanish , useId } from ' ../composables'
106
112
import type {Booleanish , ClassValue , ColorVariant , InputSize } from ' ../types'
113
+ import {isEmptySlot } from ' ../utils'
107
114
import BButton from ' ./BButton/BButton.vue'
108
115
import BCloseButton from ' ./BButton/BCloseButton.vue'
109
116
import BTransition from ' ./BTransition/BTransition.vue'
@@ -211,12 +218,10 @@ const emit = defineEmits<BModalEmits>()
211
218
212
219
const slots = useSlots ()
213
220
214
- const isActive = ref (false )
215
-
216
221
const computedId = useId (toRef (props , ' id' ), ' modal' )
217
222
218
223
const busyBoolean = useBooleanish (toRef (props , ' busy' ))
219
- // const lazyBoolean = useBooleanish(toRef(props, 'lazy'))
224
+ const lazyBoolean = useBooleanish (toRef (props , ' lazy' ))
220
225
const cancelDisabledBoolean = useBooleanish (toRef (props , ' cancelDisabled' ))
221
226
const centeredBoolean = useBooleanish (toRef (props , ' centered' ))
222
227
const hideBackdropBoolean = useBooleanish (toRef (props , ' hideBackdrop' ))
@@ -234,7 +239,9 @@ const scrollableBoolean = useBooleanish(toRef(props, 'scrollable'))
234
239
const titleSrOnlyBoolean = useBooleanish (toRef (props , ' titleSrOnly' ))
235
240
const staticBoolean = useBooleanish (toRef (props , ' static' ))
236
241
242
+ const isActive = ref (false )
237
243
const element = ref <HTMLElement | null >(null )
244
+ const lazyLoadCompleted = ref (false )
238
245
239
246
const modalClasses = computed (() => [
240
247
props .modalClass ,
@@ -304,18 +311,24 @@ const onBeforeEnter = () => emit('show')
304
311
const onAfterEnter = () => {
305
312
isActive .value = true
306
313
emit (' shown' )
314
+ if (lazyBoolean .value === true ) lazyLoadCompleted .value = true
307
315
}
308
316
const onBeforeLeave = () => emit (' hide' )
309
317
const onLeave = () => {
310
318
isActive .value = false
311
319
}
312
- const onAfterLeave = () => emit (' hidden' )
320
+ const onAfterLeave = () => {
321
+ emit (' hidden' )
322
+ if (lazyBoolean .value === true ) lazyLoadCompleted .value = false
323
+ }
313
324
314
325
watch (
315
326
() => modelValueBoolean .value ,
316
327
(newValue ) => {
317
- if (newValue === true && ! noFocusBoolean .value && element .value !== null ) {
318
- element .value .focus ()
328
+ if (newValue === true && ! noFocusBoolean .value ) {
329
+ nextTick (() => {
330
+ if (element .value !== null ) element .value .focus ()
331
+ })
319
332
}
320
333
}
321
334
)
@@ -328,6 +341,10 @@ export default {
328
341
</script >
329
342
330
343
<style lang="scss" scoped>
344
+ .modal {
345
+ display : block ;
346
+ }
347
+
331
348
.modal-dialog {
332
349
z-index : 1051 ;
333
350
}
0 commit comments