question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TextArea and TextInput can't be pre-populated with value

See original GitHub issue

What 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:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
EAlexRojascommented, Jun 18, 2019

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 value prop is being ignored.

value prop is part of others (https://github.com/carbon-design-system/carbon/blob/master/packages/react/src/components/TextArea/TextArea.js#L51) but then, the value passed to the actual textarea is 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 value and defaultValue props should be just passed as is to the textarea (?) or at least initialize the internal state with the value from the value prop (?)


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

2reactions
emyarodcommented, Jun 11, 2019

defaultValue is 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 supporting defaultValue as a prop for multiple versions now, I’m going to leave the API unchanged and just pass defaultValue in as the initial value for the components

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found