Skip to content

Commit b857ef0

Browse files
committed
Support all modal events.
1 parent 5dc64b6 commit b857ef0

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

dev/pages/Home.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@
129129
<bs-modal
130130
v-if="modalShown"
131131
title="Modal"
132+
@hide="onModalHide"
132133
@hidden="modalShown = false"
133134
>
134135
<template #body>
@@ -352,6 +353,11 @@ export default defineComponent({
352353
onCheckboxChange(): void {
353354
console.log('Checkbox change, value: ' + this.inputCheckbox)
354355
},
356+
onModalHide(event: Event): void {
357+
// if you want to prevent the modal from closing, you can use event.preventDefault()
358+
// event.preventDefault()
359+
console.log(event)
360+
},
355361
},
356362
})
357363
</script>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bootstrap-vue-wrapper",
3-
"version": "2.1.16",
3+
"version": "2.1.17",
44
"description": "Bootstrap 5 components in Vue3 wrapper.",
55
"module": "./dist/bootstrap-vue-wrapper.js",
66
"types": "./dist/index.d.ts",

src/components/bs-modal/BsModal.vue

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,17 @@ export default defineComponent({
5858
default: false,
5959
},
6060
},
61-
emits: ['shown', 'hidden'],
61+
emits: ['show', 'shown', 'hide', 'hidden', 'hidePrevented'],
6262
mounted() {
6363
const modalElement = this.$refs.modalRef as HTMLElement
6464
Modal.getOrCreateInstance(modalElement).show()
6565
66-
modalElement.addEventListener('shown.bs.modal', this.onShown)
67-
modalElement.addEventListener('hidden.bs.modal', this.onHidden)
66+
// https://getbootstrap.com/docs/5.3/components/modal/#events
67+
modalElement.addEventListener('show.bs.modal', (e) => this.$emit('show', e))
68+
modalElement.addEventListener('shown.bs.modal', (e) => this.$emit('shown', e))
69+
modalElement.addEventListener('hide.bs.modal', (e) => this.$emit('hide', e))
70+
modalElement.addEventListener('hidden.bs.modal', (e) => this.$emit('hidden', e))
71+
modalElement.addEventListener('hidePrevented.bs.modal', (e) => this.$emit('hidePrevented', e))
6872
},
6973
methods: {
7074
/**
@@ -75,18 +79,6 @@ export default defineComponent({
7579
7680
Modal.getOrCreateInstance(modalElement).hide()
7781
},
78-
/**
79-
* Shown event.
80-
*/
81-
onShown(): void {
82-
this.$emit('shown')
83-
},
84-
/**
85-
* Hidden event.
86-
*/
87-
onHidden(): void {
88-
this.$emit('hidden')
89-
},
9082
},
9183
})
9284
</script>

0 commit comments

Comments
 (0)