You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
That's because the type of the field's onBlur function is () => void. This is reasonable because in react-hook-form that function is used to programmatically blur an input, not to hook into an event. However below you overwrite react-hook-formuseController's onBlur function to support passing events:
The problem is that return type of field property is ControllerRenderProps whose onBlur function is () => void but should be something like (...event: any[]) => void
The issue lies in the return type of the field property, which is ControllerRenderProps. The onBlur function within it is specified as () => void, yet it ought to be defined as (...event: any[]) => void.
What you were expecting:
I expected that the
onBlur
event handler on NumberInput component would receive an event as an argument.What happened instead:
The function provided to the
onBlur
prop receivesundefined
instead of theSyntheticBaseEvent
.Steps to reproduce:
Simply add the following prop to the NumberInput component.
Related code:
Here is the implementation that causes such behavior
react-admin/packages/ra-ui-materialui/src/input/NumberInput.tsx
Lines 116 to 119 in 10cc321
Where I would expect it to be just like the
handleFocus
function.react-admin/packages/ra-ui-materialui/src/input/NumberInput.tsx
Lines 109 to 112 in 10cc321
However, it's not straightforward to fix. Simple solution as below works but raises typescript error
TS2554: Expected 0 arguments, but got 1
That's because the type of the
field
'sonBlur
function is() => void
. This is reasonable because inreact-hook-form
that function is used to programmatically blur an input, not to hook into an event. However below you overwritereact-hook-form
useController
'sonBlur
function to support passing events:react-admin/packages/ra-core/src/form/useInput.ts
Lines 97 to 102 in 54defed
Then you pass it to the return object of
useInput
hookreact-admin/packages/ra-core/src/form/useInput.ts
Lines 115 to 128 in 54defed
The problem is that return type of
field
property isControllerRenderProps
whoseonBlur
function is() => void
but should be something like(...event: any[]) => void
The issue lies in the return type of the
field
property, which isControllerRenderProps
. TheonBlur
function within it is specified as() => void
, yet it ought to be defined as(...event: any[]) => void
.react-admin/packages/ra-core/src/form/useInput.ts
Lines 155 to 161 in 54defed
Other information:
That behavior was also observed in the AutocompleteInput component.
Environment
The text was updated successfully, but these errors were encountered: