File tree Expand file tree Collapse file tree 3 files changed +44
-2
lines changed
src/components/VueFinalModal Expand file tree Collapse file tree 3 files changed +44
-2
lines changed Original file line number Diff line number Diff line change 1+ <script setup lang="ts">
2+ import { VueFinalModal } from ' ~/index'
3+ </script >
4+
5+ <template >
6+ <VueFinalModal v-slot =" { close }" >
7+ <button @click =" () => close()" >
8+ Close
9+ </button >
10+ </VueFinalModal >
11+ </template >
Original file line number Diff line number Diff line change 1+ import App from './App.vue'
2+ import ModalCloseByScopedSlot from './ModalCloseByScopedSlot.vue'
3+ import { createVfm , useModal } from '~/index'
4+
5+ describe ( 'Test scopedSlot' , ( ) => {
6+ it ( 'close() scoped slot ' , ( ) => {
7+ const vfm = createVfm ( )
8+ const modalName = 'modal-close-by-scoped-slot'
9+ useModal ( {
10+ defaultModelValue : true ,
11+ component : ModalCloseByScopedSlot ,
12+ attrs : { class : modalName } ,
13+ } )
14+
15+ cy . mount ( App , {
16+ global : {
17+ plugins : [ vfm ] ,
18+ stubs : { transition : false } ,
19+ } ,
20+ } ) . as ( 'app' )
21+
22+ cy . get ( `.${ modalName } ` ) . should ( 'exist' )
23+ cy . get ( `.${ modalName } ` ) . find ( 'button' ) . click ( )
24+ cy . get ( `.${ modalName } ` ) . should ( 'not.exist' )
25+ } )
26+ } )
Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ defineOptions({ inheritAttrs: false })
3535const instance = getCurrentInstance ()
3636
3737defineSlots <{
38- ' default' ? (props : { close: () => boolean }): void
38+ ' default' ? (props : { close: () => void }): void
3939 ' swipe-banner' ? (): void
4040}>()
4141
@@ -135,6 +135,11 @@ function close(): boolean {
135135 return true
136136}
137137
138+ /** Close function for scoped slot */
139+ function _close() {
140+ modelValueLocal .value = false
141+ }
142+
138143onBeforeUnmount (() => {
139144 enableBodyScroll ()
140145 arrayRemoveItem (modals , instance )
@@ -223,7 +228,7 @@ defineExpose({
223228 v-bind =" bindSwipe"
224229 @mousedown =" () => onMousedown()"
225230 >
226- <slot v-bind =" { close }" />
231+ <slot v-bind =" { close: _close }" />
227232
228233 <div
229234 v-if =" showSwipeBanner"
You can’t perform that action at this time.
0 commit comments