TextArea and TextInput can't be pre-populated with value
See original GitHub issueWhat package(s) are you using?
-
carbon-components- 10.3.0 -
carbon-components-react- 7.3.0
Detailed description
Since I’ve updated carbon-components to 10.3.0 and carbon-components-react to 7.3.0, both the TextInput and the TextArea components don’t initially pass value props down to the actual elements - which means the fields cannot be prepopulated.
This does not happen in previous versions - to see this yourself, use the CodeSandbox below and use 10.2.0/7.2.0. There, the fields are populated with whatever you pass as value to the Carbon component.
I can see the issue in the latest Chrome and Firefox.
Steps to reproduce the issue
See this reduced code snippet in CodeSandbox.
Notes
When looking at the tree using the React DevTools, you can see the Carbon components receive the value prop, but the <input>/<textarea> elements always get an empty string for their value.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:12 (7 by maintainers)
Top Results From Across the Web
Can't pre-populate textarea fields [duplicate]
The form is pre-populated by setting the value attribute of the fields to the data pulled back from the database. This works fine...
Read more >Chapter 18 Forms and Form Fields
Fields created by <input> tags with a type of text or password , as well as textarea tags, share a common interface. Their...
Read more >Flow Screen Input Component: Long Text Area
Pre -populated value for the component. If the associated screen isn't executed or the conditions for component visibility aren't met, the stored value...
Read more >Pre Populated Values (Date,Text Area) in Lightning by ...
1 Answer 1 ... From the documentation on force:createRecord : Prepopulating rich text fields is unsupported. It might work for simple values, but ......
Read more ><input>: The Input (Form Input) element - HTML
How an <input> works varies considerably depending on the value of its type ... Looks like a text input, but has validation parameters...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Hi everybody, The PR https://github.com/carbon-design-system/carbon/pull/3015 did not fix the issue. It actually introduced a regression.
I created examples based in the code snipped in this issue, both use the same code but different versions of carbon-components / carbon-components-react:
I think that the main issue is that the
valueprop is being ignored.valueprop is part ofothers(https://github.com/carbon-design-system/carbon/blob/master/packages/react/src/components/TextArea/TextArea.js#L51) but then, the value passed to the actualtextareais an internal state (initialized now with ‘defaultValue’) (https://github.com/carbon-design-system/carbon/blob/master/packages/react/src/components/TextArea/TextArea.js#L140)Maybe, as in version 10.2.0 / 7.2.0, the
valueanddefaultValueprops should be just passed as is to the textarea (?) or at least initialize the internal state with the value from thevalueprop (?)In any case, as you can see in the code snippets, there is a regression here. I hope this helps to find a solution.
@emyarod @asudoh
defaultValueis already spread as a prop for the input field but it’s just not being taken as the initial state since the hooks refactor. given that we’ve been supportingdefaultValueas a prop for multiple versions now, I’m going to leave the API unchanged and just passdefaultValuein as the initial value for the components