33
44import { Slot } from '@radix-ui/react-slot' ;
55import { useEffect , useId , useRef , useState } from 'react' ;
6- import { capitalize , getEventValue , isEqual , omitUndefined , toArray } from 'skyroc-utils' ;
6+ import { capitalize , getEventValue , isEqual , isNil , omitUndefined , toArray } from 'skyroc-utils' ;
77
88import type { InternalFormInstance } from './FieldContext' ;
99import { useFieldContext } from './FieldContext' ;
10+ import { ChangeTag } from './form-core/event' ;
1011import type { InternalFieldProps } from './types/field' ;
1112import type { StoreValue } from './types/formStore' ;
1213
@@ -120,8 +121,8 @@ function Field<Values = any>(props: InternalFieldProps<Values>) {
120121
121122 useEffect ( ( ) => {
122123 const unregister = registerField ( {
123- changeValue : newValue => {
124- if ( ! normalizedChangedRef . current ) return ;
124+ changeValue : ( newValue , __ , ___ , mask ) => {
125+ if ( ! normalizedChangedRef . current && mask === ChangeTag . Value ) return ;
125126
126127 normalizedChangedRef . current = false ;
127128
@@ -138,7 +139,7 @@ function Field<Values = any>(props: InternalFieldProps<Values>) {
138139 if ( unControlledValueChange ) {
139140 unControlledValueChange ( cref . current , newValue ) ;
140141 } else {
141- cref . current . value = newValue as any ;
142+ cref . current . value = isNil ( newValue ) ? '' : ( newValue as any ) ;
142143 }
143144 }
144145 }
0 commit comments