fix: when multiple pop-ups exist at the same time, clicking will close all (#4548)
							parent
							
								
									d1e1256202
								
							
						
					
					
						commit
						3572ce1538
					
				|  | @ -1,7 +1,7 @@ | ||||||
| <script lang="ts" setup> | <script lang="ts" setup> | ||||||
| import type { DrawerProps, ExtendedDrawerApi } from './drawer'; | import type { DrawerProps, ExtendedDrawerApi } from './drawer'; | ||||||
| 
 | 
 | ||||||
| import { ref, watch } from 'vue'; | import { provide, ref, useId, watch } from 'vue'; | ||||||
| 
 | 
 | ||||||
| import { | import { | ||||||
|   useIsMobile, |   useIsMobile, | ||||||
|  | @ -33,9 +33,13 @@ const props = withDefaults(defineProps<Props>(), { | ||||||
|   drawerApi: undefined, |   drawerApi: undefined, | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
|  | const id = useId(); | ||||||
|  | provide('DISMISSABLE_DRAWER_ID', id); | ||||||
|  | 
 | ||||||
| const wrapperRef = ref<HTMLElement>(); | const wrapperRef = ref<HTMLElement>(); | ||||||
| const { $t } = useSimpleLocale(); | const { $t } = useSimpleLocale(); | ||||||
| const { isMobile } = useIsMobile(); | const { isMobile } = useIsMobile(); | ||||||
|  | 
 | ||||||
| const state = props.drawerApi?.useStore?.(); | const state = props.drawerApi?.useStore?.(); | ||||||
| 
 | 
 | ||||||
| const { | const { | ||||||
|  | @ -83,8 +87,8 @@ function escapeKeyDown(e: KeyboardEvent) { | ||||||
| // pointer-down-outside | // pointer-down-outside | ||||||
| function pointerDownOutside(e: Event) { | function pointerDownOutside(e: Event) { | ||||||
|   const target = e.target as HTMLElement; |   const target = e.target as HTMLElement; | ||||||
|   const dismissableDrawer = !!target?.dataset.dismissableDrawer; |   const dismissableDrawer = target?.dataset.dismissableDrawer; | ||||||
|   if (!closeOnClickModal.value || !dismissableDrawer) { |   if (!closeOnClickModal.value || dismissableDrawer !== id) { | ||||||
|     e.preventDefault(); |     e.preventDefault(); | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -1,7 +1,7 @@ | ||||||
| <script lang="ts" setup> | <script lang="ts" setup> | ||||||
| import type { ExtendedModalApi, ModalProps } from './modal'; | import type { ExtendedModalApi, ModalProps } from './modal'; | ||||||
| 
 | 
 | ||||||
| import { computed, nextTick, ref, watch } from 'vue'; | import { computed, nextTick, provide, ref, useId, watch } from 'vue'; | ||||||
| 
 | 
 | ||||||
| import { | import { | ||||||
|   useIsMobile, |   useIsMobile, | ||||||
|  | @ -40,6 +40,10 @@ const dialogRef = ref(); | ||||||
| const headerRef = ref(); | const headerRef = ref(); | ||||||
| const footerRef = ref(); | const footerRef = ref(); | ||||||
| 
 | 
 | ||||||
|  | const id = useId(); | ||||||
|  | 
 | ||||||
|  | provide('DISMISSABLE_MODAL_ID', id); | ||||||
|  | 
 | ||||||
| const { $t } = useSimpleLocale(); | const { $t } = useSimpleLocale(); | ||||||
| const { isMobile } = useIsMobile(); | const { isMobile } = useIsMobile(); | ||||||
| const state = props.modalApi?.useStore?.(); | const state = props.modalApi?.useStore?.(); | ||||||
|  | @ -141,8 +145,8 @@ function handerOpenAutoFocus(e: Event) { | ||||||
| // pointer-down-outside | // pointer-down-outside | ||||||
| function pointerDownOutside(e: Event) { | function pointerDownOutside(e: Event) { | ||||||
|   const target = e.target as HTMLElement; |   const target = e.target as HTMLElement; | ||||||
|   const isDismissableModal = !!target?.dataset.dismissableModal; |   const isDismissableModal = target?.dataset.dismissableModal; | ||||||
|   if (!closeOnClickModal.value || !isDismissableModal) { |   if (!closeOnClickModal.value || isDismissableModal !== id) { | ||||||
|     e.preventDefault(); |     e.preventDefault(); | ||||||
|     e.stopPropagation(); |     e.stopPropagation(); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  | @ -1,11 +1,14 @@ | ||||||
| <script setup lang="ts"> | <script setup lang="ts"> | ||||||
|  | import { inject } from 'vue'; | ||||||
|  | 
 | ||||||
| import { useScrollLock } from '@vben-core/composables'; | import { useScrollLock } from '@vben-core/composables'; | ||||||
| 
 | 
 | ||||||
| useScrollLock(); | useScrollLock(); | ||||||
|  | const id = inject('DISMISSABLE_MODAL_ID'); | ||||||
| </script> | </script> | ||||||
| <template> | <template> | ||||||
|   <div |   <div | ||||||
|  |     :data-dismissable-modal="id" | ||||||
|     class="bg-overlay fixed inset-0 z-[1000]" |     class="bg-overlay fixed inset-0 z-[1000]" | ||||||
|     data-dismissable-modal="true" |  | ||||||
|   ></div> |   ></div> | ||||||
| </template> | </template> | ||||||
|  |  | ||||||
|  | @ -1,11 +1,14 @@ | ||||||
| <script setup lang="ts"> | <script setup lang="ts"> | ||||||
|  | import { inject } from 'vue'; | ||||||
|  | 
 | ||||||
| import { useScrollLock } from '@vben-core/composables'; | import { useScrollLock } from '@vben-core/composables'; | ||||||
| 
 | 
 | ||||||
| useScrollLock(); | useScrollLock(); | ||||||
|  | const id = inject('DISMISSABLE_DRAWER_ID'); | ||||||
| </script> | </script> | ||||||
| <template> | <template> | ||||||
|   <div |   <div | ||||||
|  |     :data-dismissable-drawer="id" | ||||||
|     class="bg-overlay fixed inset-0 z-[1000]" |     class="bg-overlay fixed inset-0 z-[1000]" | ||||||
|     data-dismissable-drawer="true" |  | ||||||
|   ></div> |   ></div> | ||||||
| </template> | </template> | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 Vben
						Vben