@@ -3,6 +3,7 @@ import { ref, provide, defineComponent, inject, watch, reactive, computed, watch
3
3
import { type ImagePreviewType , mergeDefaultValue } from './Image' ;
4
4
import Preview from './Preview' ;
5
5
import type { PreviewProps } from './Preview' ;
6
+ import useMergedState from '../../_util/hooks/useMergedState' ;
6
7
7
8
export interface PreviewGroupPreview
8
9
extends Omit < ImagePreviewType , 'icons' | 'mask' | 'maskClassName' > {
@@ -85,10 +86,14 @@ const Group = defineComponent({
85
86
const current = ref < number > ( ) ;
86
87
87
88
const previewVisible = computed ( ( ) => preview . value . visible ) ;
88
- const onPreviewVisibleChange = computed ( ( ) => preview . value . onVisibleChange ) ;
89
89
const getPreviewContainer = computed ( ( ) => preview . value . getContainer ) ;
90
-
91
- const isShowPreview = ref ( ! ! previewVisible . value ) ;
90
+ const onPreviewVisibleChange = ( val , preval ) => {
91
+ preview . value . onVisibleChange ?.( val , preval ) ;
92
+ } ;
93
+ const [ isShowPreview , setShowPreview ] = useMergedState ( ! ! previewVisible . value , {
94
+ value : previewVisible ,
95
+ onChange : onPreviewVisibleChange ,
96
+ } ) ;
92
97
93
98
const mousePosition = ref < { x : number ; y : number } > ( null ) ;
94
99
const isControlled = computed ( ( ) => previewVisible . value !== undefined ) ;
@@ -115,9 +120,6 @@ const Group = defineComponent({
115
120
const setMousePosition = ( val : null | { x : number ; y : number } ) => {
116
121
mousePosition . value = val ;
117
122
} ;
118
- const setShowPreview = ( val : boolean ) => {
119
- isShowPreview . value = val ;
120
- } ;
121
123
122
124
const registerImage = ( id : number , url : string , canPreview = true ) => {
123
125
const unRegister = ( ) => {
@@ -132,16 +134,10 @@ const Group = defineComponent({
132
134
133
135
const onPreviewClose = ( e : any ) => {
134
136
e ?. stopPropagation ( ) ;
135
- isShowPreview . value = false ;
136
- mousePosition . value = null ;
137
+ setShowPreview ( false ) ;
138
+ setMousePosition ( null ) ;
137
139
} ;
138
140
139
- watch ( previewVisible , ( ) => {
140
- isShowPreview . value = ! ! previewVisible . value ;
141
- } ) ;
142
- watch ( isShowPreview , ( val , preVal ) => {
143
- onPreviewVisibleChange . value ( val , preVal ) ;
144
- } ) ;
145
141
watch (
146
142
currentControlledKey ,
147
143
val => {
0 commit comments