Skip to content

Commit

Permalink
fix: #424
Browse files Browse the repository at this point in the history
  • Loading branch information
hunterliu1003 committed Feb 14, 2024
1 parent 8381e14 commit 175b5ab
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<script setup lang="ts">
import { VueFinalModal } from '~/index'
</script>

<template>
<VueFinalModal v-slot="{ close }">
<button @click="() => close()">
Close
</button>
</VueFinalModal>
</template>
26 changes: 26 additions & 0 deletions packages/vue-final-modal/cypress/components/scopedSlot.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import App from './App.vue'
import ModalCloseByScopedSlot from './ModalCloseByScopedSlot.vue'
import { createVfm, useModal } from '~/index'

describe('Test scopedSlot', () => {
it('close() scoped slot ', () => {
const vfm = createVfm()
const modalName = 'modal-close-by-scoped-slot'
useModal({
defaultModelValue: true,
component: ModalCloseByScopedSlot,
attrs: { class: modalName },
})

cy.mount(App, {
global: {
plugins: [vfm],
stubs: { transition: false },
},
}).as('app')

cy.get(`.${modalName}`).should('exist')
cy.get(`.${modalName}`).find('button').click()
cy.get(`.${modalName}`).should('not.exist')
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ defineOptions({ inheritAttrs: false })
const instance = getCurrentInstance()
defineSlots<{
'default'?(props: { close: () => boolean }): void
'default'?(props: { close: () => void }): void
'swipe-banner'?(): void
}>()
Expand Down Expand Up @@ -135,6 +135,11 @@ function close(): boolean {
return true
}
/** Close function for scoped slot */
function _close() {
modelValueLocal.value = false
}
onBeforeUnmount(() => {
enableBodyScroll()
arrayRemoveItem(modals, instance)
Expand Down Expand Up @@ -223,7 +228,7 @@ defineExpose({
v-bind="bindSwipe"
@mousedown="() => onMousedown()"
>
<slot v-bind="{ close }" />
<slot v-bind="{ close: _close }" />

<div
v-if="showSwipeBanner"
Expand Down

0 comments on commit 175b5ab

Please sign in to comment.