11import * as React from 'react' ;
2+ import { useForm , FormProvider , useFieldArray } from 'react-hook-form' ;
23import { CoreAdminContext } from '../core' ;
34import { Form } from './Form' ;
45import { InputProps , useInput } from './useInput' ;
@@ -7,12 +8,15 @@ export default {
78 title : 'ra-core/form/useInput' ,
89} ;
910
10- const Input = ( props : InputProps ) => {
11+ const Input = ( props : InputProps & { log ?: boolean } ) => {
12+ const { label, log } = props ;
1113 const { id, field, fieldState } = useInput ( props ) ;
12-
14+ if ( log ) {
15+ console . log ( `Input ${ id } rendered:` ) ;
16+ }
1317 return (
1418 < label htmlFor = { id } >
15- { id } : < input id = { id } { ...field } />
19+ { label ?? id } : < input id = { id } { ...field } />
1620 { fieldState . error && < span > { fieldState . error . message } </ span > }
1721 </ label >
1822 ) ;
@@ -86,3 +90,38 @@ DefaultValue.argTypes = {
8690 control : { type : 'select' } ,
8791 } ,
8892} ;
93+
94+ export const Large = ( ) => {
95+ const [ submittedData , setSubmittedData ] = React . useState < any > ( ) ;
96+ const fields = Array . from ( { length : 15 } ) . map ( ( _ , index ) => (
97+ < Input
98+ key = { index }
99+ source = { `field${ index + 1 } ` }
100+ label = { `field${ index + 1 } ` }
101+ />
102+ ) ) ;
103+ return (
104+ < CoreAdminContext >
105+ < Form
106+ onSubmit = { data => setSubmittedData ( data ) }
107+ record = { Array . from ( { length : 15 } ) . reduce ( ( acc , _ , index ) => {
108+ acc [ `field${ index + 1 } ` ] = `value${ index + 1 } ` ;
109+ return acc ;
110+ } , { } ) }
111+ >
112+ < div
113+ style = { {
114+ display : 'flex' ,
115+ flexDirection : 'column' ,
116+ gap : '1em' ,
117+ marginBottom : '1em' ,
118+ } }
119+ >
120+ { fields }
121+ </ div >
122+ < button type = "submit" > Submit</ button >
123+ </ Form >
124+ < pre > { JSON . stringify ( submittedData , null , 2 ) } </ pre >
125+ </ CoreAdminContext >
126+ ) ;
127+ } ;
0 commit comments