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.

Grouped TextField select: value becomes undefined onChange

See original GitHub issue

When you wrap ListSubheader & MenuItems inside <TextField select /> in an element, like div, the value is lost (=undefined) on the next onChange.

  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

You are not allowed to use react fragments and when you use an element to dynamically map to a single root, value becomes undefined onChange.

Expected Behavior 🤔

It should be possible to either use fragment or wrap the above components in another element.

Steps to Reproduce 🕹

https://codesandbox.io/s/wizardly-snowflake-l7lu4

Steps:

  1. open the example above
  2. change the select value
  3. see error

Your Environment 🌎

Tech Version
Material-UI v4.8.0
React 16.8.4
Browser firefox 71
TypeScript 3.3.3

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
akommcommented, Dec 16, 2019

Thanks.

The example did not really help, as it uses static definitions, not dynamic.

But I figured it out now myself - no intermediary component needed (also no dead value).

For those, who might seek for the solution: https://codesandbox.io/s/silly-mclaren-k7qul

1reaction
oliviertassinaricommented, Dec 16, 2019

You have to apply the value prop on the outer most element, this is related to #14943.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Grouped TextField select: value becomes undefined onChange
When you wrap ListSubheader & MenuItems inside in an element, like div, the value is lost (=undefined) on the next onChange.
Read more >
Material-UI Select e.target.value is undefined - Stack Overflow
The reason e.target.value was returning undefined was, as others mentioned, due to the fact that MenuItem wasn't a direct child of Select ....
Read more >
Forms - React
An input form element whose value is controlled by React in this way is called a “controlled component”. For example, if we want...
Read more >
Form Select | Components - BootstrapVue
Custom component using cross-browser custom styles. Optionally generate entries based on an array, array of objects.
Read more >
Form - Examples - Components - Atlassian Design System
Any component with a value and onChange handler can be a field. The component renders inside a field and adds an entry to...
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