Dismiss gallery lightbox on background click (#752)

* Dismiss gallery on background click

* Add vitest tests
This commit is contained in:
bymyself
2024-09-06 23:32:56 -07:00
committed by GitHub
parent 56f3842045
commit 08a1fd0056
2 changed files with 106 additions and 0 deletions

View File

@@ -11,6 +11,13 @@
fullScreen
circular
:showThumbnails="false"
:pt="{
mask: {
onMousedown: onMaskMouseDown,
onMouseup: onMaskMouseUp,
'data-mask': true
}
}"
>
<template #item="{ item }">
<ComfyImage
@@ -40,6 +47,24 @@ const props = defineProps<{
activeIndex: number
}>()
let maskMouseDownTarget: EventTarget | null = null
const onMaskMouseDown = (event: MouseEvent) => {
maskMouseDownTarget = event.target
}
const onMaskMouseUp = (event: MouseEvent) => {
const maskEl = document.querySelector('[data-mask]')
if (
galleryVisible.value &&
maskMouseDownTarget === event.target &&
maskMouseDownTarget === maskEl
) {
galleryVisible.value = false
handleVisibilityChange(false)
}
}
watch(
() => props.activeIndex,
(index) => {