@@ -22,6 +22,7 @@ import {
2222 tasty ,
2323} from '../../../tasty' ;
2424import { FieldBaseProps } from '../../../shared' ;
25+ import { useFieldProps , useFormProps } from '../Form/index' ;
2526import { wrapWithField } from '../wrapper' ;
2627
2728import type { AriaTextFieldProps } from '@react-types/textfield' ;
@@ -138,32 +139,43 @@ function extractContents(element, callback) {
138139
139140function FileInput ( props : CubeFileInputProps , ref ) {
140141 props = useProviderProps ( props ) ;
142+ props = useFormProps ( props ) ;
143+
144+ const onLocalChange = useCallback (
145+ ( event ) => {
146+ const value = event . target . value ;
147+
148+ if ( type === 'file' ) {
149+ onChange ?.( value ) ;
150+ } else if ( onChange ) {
151+ extractContents ( event . target , onChange ) ;
152+ }
153+
154+ setValue ( value ) ;
155+ } ,
156+ [ props . onChange ] ,
157+ ) ;
158+
159+ props = useFieldProps (
160+ { ...props , onChange : onLocalChange } ,
161+ {
162+ defaultValidationTrigger : 'onChange' ,
163+ valuePropsMapper : ( { value, onChange } ) => ( {
164+ onChange,
165+ value : undefined ,
166+ } ) ,
167+ } ,
168+ ) ;
141169
142170 let {
143171 id,
144172 name,
145173 qa,
146- qaVal,
147174 onChange,
148175 placeholder,
149176 inputRef,
150- label,
151- extra,
152- labelPosition,
153- isRequired,
154- necessityIndicator,
155- necessityLabel,
156- labelStyles,
157- labelProps,
158177 isDisabled,
159- validationState,
160- message,
161- description,
162- requiredMark,
163- tooltip,
164- isHidden,
165178 inputStyles,
166- labelSuffix,
167179 type = 'file' ,
168180 inputProps,
169181 accept,
@@ -180,21 +192,6 @@ function FileInput(props: CubeFileInputProps, ref) {
180192
181193 let styles = extractStyles ( otherProps , CONTAINER_STYLES ) ;
182194
183- const onLocalChange = useCallback (
184- ( event ) => {
185- const value = event . target . value ;
186-
187- if ( type === 'file' ) {
188- onChange ?.( value ) ;
189- } else if ( onChange ) {
190- extractContents ( event . target , onChange ) ;
191- }
192-
193- setValue ( value ) ;
194- } ,
195- [ onChange ] ,
196- ) ;
197-
198195 // Expose imperative interface for ref
199196 useImperativeHandle ( ref , ( ) => ( {
200197 ...createFocusableRef ( domRef , inputRef ) ,
@@ -216,7 +213,7 @@ function FileInput(props: CubeFileInputProps, ref) {
216213 const fileInput = (
217214 < FileInputElement
218215 ref = { domRef }
219- qa = { qa || ' FileInput' }
216+ qa = " FileInput"
220217 styles = { inputStyles }
221218 isDisabled = { isDisabled }
222219 mods = { {
@@ -237,7 +234,6 @@ function FileInput(props: CubeFileInputProps, ref) {
237234 data-element = "Input"
238235 type = "file"
239236 tabIndex = { - 1 }
240- onChange = { onLocalChange }
241237 onDragEnter = { ( ) => {
242238 setDragHover ( true ) ;
243239 } }
0 commit comments