@@ -13,6 +13,8 @@ import { Field, FieldType, Metadata, UseFindUniqueHook, UseMutationHook, UseQuer
13
13
import { useZenstackUIProvider } from '../utils/provider' ;
14
14
import { getIdField , getModelFields } from '../utils/utils' ;
15
15
16
+ const LOADING_PLACEHOLDER = 'Loading...' ;
17
+
16
18
// Form ref type
17
19
export interface ZenstackFormRef {
18
20
form : ReturnType < typeof useForm >
@@ -548,7 +550,7 @@ const ZenstackFormInputInternal = (props: ZenstackFormInputProps) => {
548
550
} ;
549
551
} ) ;
550
552
} else {
551
- labelData = [ { label : 'Loading...' , value : 'Loading...' } ] ;
553
+ labelData = [ { label : LOADING_PLACEHOLDER , value : LOADING_PLACEHOLDER } ] ;
552
554
}
553
555
}
554
556
@@ -572,7 +574,7 @@ const ZenstackFormInputInternal = (props: ZenstackFormInputProps) => {
572
574
}
573
575
574
576
let placeholder = field . placeholder ;
575
- if ( props . isLoadingInitialData ) placeholder = 'Loading...' ;
577
+ if ( props . isLoadingInitialData ) placeholder = LOADING_PLACEHOLDER ;
576
578
577
579
// Create wrapped onChange handler
578
580
// This handler is used to reset dependent fields when the main field changes (using dependsOn from metadata)
@@ -601,15 +603,30 @@ const ZenstackFormInputInternal = (props: ZenstackFormInputProps) => {
601
603
const dirtyClassName = isDirty ? 'dirty' : '' ;
602
604
const combinedClassName = `${ originalClassName } ${ dirtyClassName } ` . trim ( ) ;
603
605
604
- return React . cloneElement ( props . customElement , {
606
+ // Create base props that we want to pass
607
+ const baseProps = {
605
608
...props . form . getInputProps ( fieldName ) ,
606
- onChange : handleChange ,
609
+ ' onChange' : handleChange ,
607
610
required,
608
- key : props . form . key ( fieldName ) ,
609
- className : combinedClassName ,
610
- disabled : isDisabled ,
611
- placeholder : placeholder ,
612
- } ) ;
611
+ 'key' : props . form . key ( fieldName ) ,
612
+ 'className' : combinedClassName ,
613
+ 'disabled' : isDisabled ,
614
+ 'placeholder' : placeholder ,
615
+ label,
616
+ 'data' : labelData ,
617
+ 'data-autofocus' : props . index === 0 ,
618
+ } ;
619
+
620
+ // Filter out props that are already defined in customElement
621
+ const finalProps = Object . fromEntries (
622
+ Object . entries ( baseProps ) . filter ( ( [ key ] ) =>
623
+ props . customElement ! . props [ key ] === undefined ,
624
+ ) ,
625
+ ) ;
626
+ // For custom elements, we need to prioritize the loading placeholder
627
+ if ( props . isLoadingInitialData ) finalProps . placeholder = LOADING_PLACEHOLDER ;
628
+
629
+ return React . cloneElement ( props . customElement , finalProps ) ;
613
630
}
614
631
615
632
return (
0 commit comments