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
Hi team,
I was using react-hook-form alongside the @carbon/react components, specifically TextInput and TextArea . I noticed that TextArea checks its ref for a value alongside defaultValue and value props, but TextInput does not do this. Is this intentional? In this case I am using a package (react-hook-form), and I believe the register function from this library utilizes the ref prop, something that is taken into account in TextArea but not in TextInput.
Package
@carbon/react
Browser
Chrome
Package version
v1.74.0
React version
v18.3.1
Description
Hi team,
I was using react-hook-form alongside the @carbon/react components, specifically TextInput and TextArea . I noticed that TextArea checks its ref for a value alongside defaultValue and value props, but TextInput does not do this. Is this intentional? In this case I am using a package (react-hook-form), and I believe the
register
function from this library utilizes theref
prop, something that is taken into account in TextArea but not in TextInput.This causes for example the following behavior: https://stackblitz.com/edit/github-itebggga-lkm9xkdl?file=src%2FApp.tsx
Where TextArea has the correct character counter, but TextInput doesn't.
TextArea code (this code doesn't exist in TextInput): https://github.com/carbon-design-system/carbon/blob/main/packages/react/src/components/TextArea/TextArea.tsx#L200
Reproduction/example
https://stackblitz.com/edit/github-itebggga-lkm9xkdl?file=src%2FApp.tsx
Steps to reproduce
Without react-hook-form:
useRef
hookTextInput
componentuseEffect
hook check ifref.current
is not null, set a value toref.current.value
Result:
With react-hook-form
useForm
withdefaultValues
register
apiResult:
Suggested Severity
Severity 4 = Unrelated to a user task, has a workaround or does not need a workaround.
Application/PAL
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: