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

Commit 45969c8

Browse files
committed
feat(BOffcanvas): adds teleport to property.
1 parent f097d76 commit 45969c8

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

packages/bootstrap-vue-next/src/components/BOffcanvas/BOffcanvas.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="{
@@ -62,7 +62,7 @@
6262
</template>
6363

6464
<script setup lang="ts">
65-
import {computed, nextTick, ref, useSlots} from 'vue'
65+
import {computed, nextTick, ref, type RendererElement, useSlots} from 'vue'
6666
import {useEventListener, useFocus, useVModel} from '@vueuse/core'
6767
import {useBooleanish, useId} from '../../composables'
6868
import type {Booleanish, ColorVariant} from '../../types'
@@ -94,6 +94,7 @@ interface BOffcanvasProps {
9494
noFocus?: Booleanish
9595
static?: Booleanish
9696
backdropVariant?: ColorVariant | null
97+
to?: string | RendererElement | null | undefined
9798
// TODO responsive doesn't work
9899
// responsive?: Breakpoint
99100
}
@@ -114,6 +115,7 @@ const props = withDefaults(defineProps<BOffcanvasProps>(), {
114115
placement: 'start',
115116
noHeaderClose: false,
116117
noHeader: false,
118+
to: 'body',
117119
})
118120
119121
interface BOffcanvasEmits {

packages/bootstrap-vue-next/src/components/BOffcanvas/offcanvas.spec.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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 BOffcanvas from './BOffcanvas.vue'
44
import BCloseButton from '../BButton/BCloseButton.vue'
55
import BOverlay from '../BOverlay/BOverlay.vue'
@@ -8,6 +8,29 @@ describe.skip('offcanvas', () => {
88

99
// TODO afaik these tests are not finished
1010

11+
beforeEach(() => {
12+
const el = document.createElement('div')
13+
el.id = 'body-teleports'
14+
document.body.appendChild(el)
15+
})
16+
17+
afterEach(() => {
18+
document.body.outerHTML = ''
19+
})
20+
21+
it('has body teleports element set by to property', () => {
22+
const wrapper = mount(BOffcanvas, {
23+
props: {
24+
to: '#body-teleports',
25+
modelValue: true,
26+
},
27+
global: {stubs: {teleport: true}},
28+
})
29+
const div = wrapper.find('#body-teleports')
30+
const offcanvas = div.find('.offcanvas')
31+
expect(offcanvas.exists()).toBe(true)
32+
})
33+
1134
it('has static class offcanvas', () => {
1235
const wrapper = mount(BOffcanvas, {
1336
props: {

0 commit comments

Comments
 (0)