Skip to content

Commit 3d6a81e

Browse files
authored
Merge pull request #762 from devhus/main
BModal fixes
2 parents ddcf11b + 65e14f0 commit 3d6a81e

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

packages/bootstrap-vue-3/src/components/BModal.vue

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,20 @@
1818
role="dialog"
1919
:aria-labelledby="`${computedId}-label`"
2020
:aria-describedby="`${computedId}-body`"
21-
:style="{display: 'block'}"
2221
tabindex="-1"
2322
v-bind="$attrs"
2423
@keyup.esc="onEsc"
2524
>
2625
<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+
>
2835
<div v-if="!hideHeaderBoolean" class="modal-header" :class="headerClasses">
2936
<slot name="header">
3037
<component
@@ -100,10 +107,10 @@
100107

101108
<script setup lang="ts">
102109
// 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'
105111
import {useBooleanish, useId} from '../composables'
106112
import type {Booleanish, ClassValue, ColorVariant, InputSize} from '../types'
113+
import {isEmptySlot} from '../utils'
107114
import BButton from './BButton/BButton.vue'
108115
import BCloseButton from './BButton/BCloseButton.vue'
109116
import BTransition from './BTransition/BTransition.vue'
@@ -211,12 +218,10 @@ const emit = defineEmits<BModalEmits>()
211218
212219
const slots = useSlots()
213220
214-
const isActive = ref(false)
215-
216221
const computedId = useId(toRef(props, 'id'), 'modal')
217222
218223
const busyBoolean = useBooleanish(toRef(props, 'busy'))
219-
// const lazyBoolean = useBooleanish(toRef(props, 'lazy'))
224+
const lazyBoolean = useBooleanish(toRef(props, 'lazy'))
220225
const cancelDisabledBoolean = useBooleanish(toRef(props, 'cancelDisabled'))
221226
const centeredBoolean = useBooleanish(toRef(props, 'centered'))
222227
const hideBackdropBoolean = useBooleanish(toRef(props, 'hideBackdrop'))
@@ -234,7 +239,9 @@ const scrollableBoolean = useBooleanish(toRef(props, 'scrollable'))
234239
const titleSrOnlyBoolean = useBooleanish(toRef(props, 'titleSrOnly'))
235240
const staticBoolean = useBooleanish(toRef(props, 'static'))
236241
242+
const isActive = ref(false)
237243
const element = ref<HTMLElement | null>(null)
244+
const lazyLoadCompleted = ref(false)
238245
239246
const modalClasses = computed(() => [
240247
props.modalClass,
@@ -304,18 +311,24 @@ const onBeforeEnter = () => emit('show')
304311
const onAfterEnter = () => {
305312
isActive.value = true
306313
emit('shown')
314+
if (lazyBoolean.value === true) lazyLoadCompleted.value = true
307315
}
308316
const onBeforeLeave = () => emit('hide')
309317
const onLeave = () => {
310318
isActive.value = false
311319
}
312-
const onAfterLeave = () => emit('hidden')
320+
const onAfterLeave = () => {
321+
emit('hidden')
322+
if (lazyBoolean.value === true) lazyLoadCompleted.value = false
323+
}
313324
314325
watch(
315326
() => modelValueBoolean.value,
316327
(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+
})
319332
}
320333
}
321334
)
@@ -328,6 +341,10 @@ export default {
328341
</script>
329342

330343
<style lang="scss" scoped>
344+
.modal {
345+
display: block;
346+
}
347+
331348
.modal-dialog {
332349
z-index: 1051;
333350
}

0 commit comments

Comments
 (0)