|
1 | | -import { defineComponent, h, provide, ref, RendererElement, Transition, watch } from 'vue' |
| 1 | +import { |
| 2 | + defineComponent, |
| 3 | + h, |
| 4 | + provide, |
| 5 | + ref, |
| 6 | + RendererElement, |
| 7 | + Transition, |
| 8 | + vShow, |
| 9 | + watch, |
| 10 | + withDirectives, |
| 11 | +} from 'vue' |
2 | 12 |
|
3 | 13 | import { CBackdrop } from './../backdrop/CBackdrop' |
4 | 14 |
|
@@ -90,6 +100,14 @@ const CModal = defineComponent({ |
90 | 100 | default: true, |
91 | 101 | required: false, |
92 | 102 | }, |
| 103 | + /* |
| 104 | + * By default the component is unmounted after close animation, if you want to keep the component mounted set this property to false. |
| 105 | + */ |
| 106 | + unmountOnClose: { |
| 107 | + type: Boolean, |
| 108 | + default: true, |
| 109 | + required: false, |
| 110 | + }, |
93 | 111 | /** |
94 | 112 | * Toggle the visibility of alert component. |
95 | 113 | */ |
@@ -189,52 +207,57 @@ const CModal = defineComponent({ |
189 | 207 |
|
190 | 208 | provide('handleDismiss', handleDismiss) |
191 | 209 |
|
| 210 | + const modal = () => |
| 211 | + h( |
| 212 | + 'div', |
| 213 | + { |
| 214 | + class: [ |
| 215 | + 'modal', |
| 216 | + { |
| 217 | + ['fade']: props.transition, |
| 218 | + }, |
| 219 | + attrs.class, |
| 220 | + ], |
| 221 | + ref: modalRef, |
| 222 | + }, |
| 223 | + h( |
| 224 | + 'div', |
| 225 | + { |
| 226 | + class: [ |
| 227 | + 'modal-dialog', |
| 228 | + { |
| 229 | + 'modal-dialog-centered': props.alignment === 'center', |
| 230 | + [`modal-fullscreen-${props.fullscreen}-down`]: |
| 231 | + props.fullscreen && typeof props.fullscreen === 'string', |
| 232 | + 'modal-fullscreen': props.fullscreen && typeof props.fullscreen === 'boolean', |
| 233 | + ['modal-dialog-scrollable']: props.scrollable, |
| 234 | + [`modal-${props.size}`]: props.size, |
| 235 | + }, |
| 236 | + ], |
| 237 | + role: 'dialog', |
| 238 | + }, |
| 239 | + h( |
| 240 | + 'div', |
| 241 | + { class: ['modal-content', props.contentClassName], ref: modalContentRef }, |
| 242 | + slots.default && slots.default(), |
| 243 | + ), |
| 244 | + ), |
| 245 | + ) |
| 246 | + |
192 | 247 | return () => [ |
193 | 248 | h( |
194 | 249 | Transition, |
195 | 250 | { |
| 251 | + css: false, |
196 | 252 | onEnter: (el, done) => handleEnter(el, done), |
197 | 253 | onAfterEnter: () => handleAfterEnter(), |
198 | 254 | onLeave: (el, done) => handleLeave(el, done), |
199 | 255 | onAfterLeave: (el) => handleAfterLeave(el), |
200 | 256 | }, |
201 | 257 | () => |
202 | | - visible.value && |
203 | | - h( |
204 | | - 'div', |
205 | | - { |
206 | | - class: [ |
207 | | - 'modal', |
208 | | - { |
209 | | - ['fade']: props.transition, |
210 | | - }, |
211 | | - attrs.class, |
212 | | - ], |
213 | | - ref: modalRef, |
214 | | - }, |
215 | | - h( |
216 | | - 'div', |
217 | | - { |
218 | | - class: [ |
219 | | - 'modal-dialog', |
220 | | - { |
221 | | - 'modal-dialog-centered': props.alignment === 'center', |
222 | | - [`modal-fullscreen-${props.fullscreen}-down`]: |
223 | | - props.fullscreen && typeof props.fullscreen === 'string', |
224 | | - 'modal-fullscreen': props.fullscreen && typeof props.fullscreen === 'boolean', |
225 | | - ['modal-dialog-scrollable']: props.scrollable, |
226 | | - [`modal-${props.size}`]: props.size, |
227 | | - }, |
228 | | - ], |
229 | | - role: 'dialog', |
230 | | - }, |
231 | | - h( |
232 | | - 'div', |
233 | | - { class: ['modal-content', props.contentClassName], ref: modalContentRef }, |
234 | | - slots.default && slots.default(), |
235 | | - ), |
236 | | - ), |
237 | | - ), |
| 258 | + props.unmountOnClose |
| 259 | + ? visible.value && modal() |
| 260 | + : withDirectives(modal(), [[vShow, visible.value]]), |
238 | 261 | ), |
239 | 262 | props.backdrop && |
240 | 263 | h(CBackdrop, { |
|
0 commit comments