Skip to content
This repository was archived by the owner on Mar 27, 2025. It is now read-only.

Commit 1a8d11b

Browse files
committed
feat(BModal): adds teleport to property.
1 parent f097d76 commit 1a8d11b

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<teleport to="body" :disabled="staticBoolean">
2+
<teleport :to="props.to" :disabled="staticBoolean">
33
<b-transition
44
:no-fade="true"
55
:trans-props="{enterToClass: 'show'}"
@@ -90,7 +90,7 @@
9090
</template>
9191

9292
<script setup lang="ts">
93-
import {computed, ref, useSlots} from 'vue'
93+
import {computed, ref, type RendererElement, useSlots} from 'vue'
9494
import {useBooleanish, useId, useModalManager} from '../composables'
9595
import {useEventListener, useFocus, useVModel} from '@vueuse/core'
9696
import type {Booleanish, ButtonVariant, ClassValue, ColorVariant, Size} from '../types'
@@ -158,6 +158,7 @@ interface BModalProps {
158158
titleTag?: string
159159
static?: Booleanish
160160
autoFocusButton?: 'ok' | 'cancel' | 'close'
161+
to?: string | RendererElement | null | undefined
161162
}
162163
163164
const props = withDefaults(defineProps<BModalProps>(), {
@@ -208,6 +209,7 @@ const props = withDefaults(defineProps<BModalProps>(), {
208209
show: false,
209210
titleSrOnly: false,
210211
titleTag: 'h5',
212+
to: 'body',
211213
})
212214
213215
interface BModalEmits {

packages/bootstrap-vue-next/src/components/modal.spec.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,32 @@
11
import {enableAutoUnmount, mount} from '@vue/test-utils'
2-
import {afterEach, describe, expect, it} from 'vitest'
2+
import {afterEach, beforeEach, describe, expect, it} from 'vitest'
33
import BModal from './BModal.vue'
44
// import BTransition from './BTransition/BTransition.vue'
55

66
describe('modal', () => {
77
enableAutoUnmount(afterEach)
8+
9+
beforeEach(() => {
10+
const el = document.createElement('div')
11+
el.id = 'body-teleports'
12+
document.body.appendChild(el)
13+
})
14+
15+
afterEach(() => {
16+
const el = document.getElementById('body-teleports')
17+
if (el) document.body.removeChild(el)
18+
})
19+
20+
it('has body teleports element set by to property', () => {
21+
const wrapper = mount(BModal, {
22+
props: {
23+
to: '#body-teleports',
24+
},
25+
})
26+
expect(wrapper.exists()).toBe(true)
27+
expect(document.getElementById('body-teleports')?.querySelector('.modal')).not.toBe(null)
28+
})
29+
830
// Having issues getting the 'body' from the VDOM
931
it('has body element', () => {
1032
const wrapper = mount(BModal, {

0 commit comments

Comments
 (0)