@@ -3,6 +3,7 @@ import { ref, provide, defineComponent, inject, watch, reactive, computed, watch
33import { type ImagePreviewType , mergeDefaultValue } from './Image' ;
44import Preview from './Preview' ;
55import type { PreviewProps } from './Preview' ;
6+ import useMergedState from '../../_util/hooks/useMergedState' ;
67
78export interface PreviewGroupPreview
89 extends Omit < ImagePreviewType , 'icons' | 'mask' | 'maskClassName' > {
@@ -85,10 +86,14 @@ const Group = defineComponent({
8586 const current = ref < number > ( ) ;
8687
8788 const previewVisible = computed ( ( ) => preview . value . visible ) ;
88- const onPreviewVisibleChange = computed ( ( ) => preview . value . onVisibleChange ) ;
8989 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+ } ) ;
9297
9398 const mousePosition = ref < { x : number ; y : number } > ( null ) ;
9499 const isControlled = computed ( ( ) => previewVisible . value !== undefined ) ;
@@ -115,9 +120,6 @@ const Group = defineComponent({
115120 const setMousePosition = ( val : null | { x : number ; y : number } ) => {
116121 mousePosition . value = val ;
117122 } ;
118- const setShowPreview = ( val : boolean ) => {
119- isShowPreview . value = val ;
120- } ;
121123
122124 const registerImage = ( id : number , url : string , canPreview = true ) => {
123125 const unRegister = ( ) => {
@@ -132,16 +134,10 @@ const Group = defineComponent({
132134
133135 const onPreviewClose = ( e : any ) => {
134136 e ?. stopPropagation ( ) ;
135- isShowPreview . value = false ;
136- mousePosition . value = null ;
137+ setShowPreview ( false ) ;
138+ setMousePosition ( null ) ;
137139 } ;
138140
139- watch ( previewVisible , ( ) => {
140- isShowPreview . value = ! ! previewVisible . value ;
141- } ) ;
142- watch ( isShowPreview , ( val , preVal ) => {
143- onPreviewVisibleChange . value ( val , preVal ) ;
144- } ) ;
145141 watch (
146142 currentControlledKey ,
147143 val => {
0 commit comments