|
1 | 1 | <script setup>
|
2 | 2 | import { getConfig, getConfigByType } from './config'
|
3 |
| -import { inject, onBeforeUnmount, ref, computed, useAttrs, onMounted } from 'vue' |
| 3 | +import { inject, onBeforeUnmount, ref, computed, useAttrs, onMounted, watch } from 'vue' |
4 | 4 | import { useModalStack } from './modalStack'
|
5 | 5 | import ModalRenderer from './ModalRenderer.vue'
|
6 | 6 |
|
@@ -85,7 +85,7 @@ function registerEventListeners() {
|
85 | 85 | unsubscribeEventListeners.value = modalContext.value.registerEventListenersFromAttrs($attrs)
|
86 | 86 | }
|
87 | 87 |
|
88 |
| -const emits = defineEmits(['modal-event']) |
| 88 | +const emits = defineEmits(['modal-event', 'focus', 'blur', 'close', 'success']) |
89 | 89 |
|
90 | 90 | function emit(event, ...args) {
|
91 | 91 | emits('modal-event', event, ...args)
|
@@ -123,6 +123,25 @@ defineExpose({
|
123 | 123 | },
|
124 | 124 | })
|
125 | 125 |
|
| 126 | +watch( |
| 127 | + () => modalContext.value?.onTopOfStack, |
| 128 | + (onTopOfStack, previousOnTopOfStack) => { |
| 129 | + if (onTopOfStack && !previousOnTopOfStack) { |
| 130 | + emits('focus') |
| 131 | + } else if (!onTopOfStack && previousOnTopOfStack) { |
| 132 | + emits('blur') |
| 133 | + } |
| 134 | + }, |
| 135 | +) |
| 136 | +
|
| 137 | +watch( |
| 138 | + () => modalContext.value?.isOpen, |
| 139 | + (isOpen) => { |
| 140 | + isOpen ? emits('success') : emits('close') |
| 141 | + }, |
| 142 | + { immediate: true }, |
| 143 | +) |
| 144 | +
|
126 | 145 | const nextIndex = computed(() => {
|
127 | 146 | return modalStack.stack.value.find((m) => m.shouldRender && m.index > modalContext.value.index)?.index
|
128 | 147 | })
|
|
0 commit comments