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
I was debating myself if this should be reported as a bug or as a question (given that this code it's been there since 2+ years ago), but decided to go with the Bug route:
useTextField is overwriting the onChange behavior by deciding to send e.target.value as the prop instead of sending the entire SyntheticEvent object.
Yes, I understand this would be breaking change :/ - (Sorry, I don't understand why this wasn't raised long ago)
馃敠 Context
I'm trying to integrate an external library (react-hook-form) that gives me a onChange handler that is expected to receive a SyntheticEvent but it fails badly because this hook calls onChange fn with the raw value.
馃悰 Bug Report
I was debating myself if this should be reported as a bug or as a question (given that this code it's been there since 2+ years ago), but decided to go with the Bug route:
useTextField
is overwriting theonChange
behavior by deciding to sende.target.value
as the prop instead of sending the entire SyntheticEvent object.https://github.com/adobe/react-spectrum/blob/main/packages/@react-aria/textfield/src/useTextField.ts#L80
Why do I think this is a bug?
Literally any other event handler (onCopy, onCut, onSelect, onInput, etc, etc) is passed down without any modifications, see: https://github.com/adobe/react-spectrum/blob/main/packages/@react-aria/textfield/src/useTextField.ts#L88-L105
See, React SyntheticEvent: https://reactjs.org/docs/events.html#form-events
馃 Expected Behavior
onChange
to not have custom logic and to be passed down straight to the input馃槸 Current Behavior
onChange
is called with the raw value of the input when all other event handlers (ex:onInput
) are called with the SyntheticEvent object.馃拋 Possible Solution
Change
to
Yes, I understand this would be breaking change :/ - (Sorry, I don't understand why this wasn't raised long ago)
馃敠 Context
I'm trying to integrate an external library (
react-hook-form
) that gives me aonChange
handler that is expected to receive aSyntheticEvent
but it fails badly because this hook callsonChange
fn with the raw value.馃捇 Code Sample
This example does not integrate with react-hook-form, but showcases the different values we get on
onChange
vs other event handlershttps://codesandbox.io/s/optimistic-hofstadter-4zg5o?file=/src/App.js
馃實 Your Environment
The text was updated successfully, but these errors were encountered: