Skip to content

fix(modal): [modal] click the close button to add a close event #2106

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ function showModal() {
status: 'info',
messageClosable: true,
events: {
hide: () => {
Notify({
type: 'info',
title: '触发hide回调事件',
position: 'top-right'
})
},
close: () => {
Notify({
type: 'info',
Expand Down
9 changes: 8 additions & 1 deletion examples/sites/demos/pc/app/modal/message-closable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</template>

<script>
import { Button, Modal } from '@opentiny/vue'
import { Button, Modal, Notify } from '@opentiny/vue'

export default {
components: {
Expand All @@ -18,6 +18,13 @@ export default {
status: 'info',
messageClosable: true,
events: {
hide: () => {
Notify({
type: 'info',
title: '触发hide回调事件',
position: 'top-right'
})
},
close: () => {
Notify({
type: 'info',
Expand Down
8 changes: 4 additions & 4 deletions packages/renderless/src/modal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,13 +370,13 @@ export const close =
state.contentVisible = false
setTimeout(() => {
state.visible = false

let params = { type, $modal: parent }
if (events.close) {
events.close.call(parent, params)
emit('close', params)
if (events.hide) {
events.hide.call(parent, params)
} else {
emit('update:modelValue', false)
emit('close', params)
emit('hide', params)
}
}, 200)
}
Expand Down
14 changes: 7 additions & 7 deletions packages/vue/src/modal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@ export function Modal(options) {
let events = options.events || {}
let $modal
options.events = Object.assign({}, events, {
hide(params) {
events.hide && events.hide.call(this, params)
if ($modal.beforeUnmouted) {
$modal.beforeUnmouted()
}
resolve(params.type)
},
confirm(params) {
events.confirm && events.confirm.call(this, params)
},
show(params) {
events.show && events.show.call(this, params)
},
close(params) {
events.close && events.close.call(this, params)
if ($modal.beforeUnmouted) {
$modal.beforeUnmouted()
}
resolve(params.type)
}
})

Expand Down
Loading