The select tag example from official React-documentation gives a warning
See original GitHub issueImplemented “The select Tag” example from https://reactjs.org/docs/forms.html and get this warning:
Warning: The value prop supplied to select must be a scalar value if multiple is false.
I use 16.6.0-pre.61-kotlin-1.3.0: compile ‘org.jetbrains:kotlin-react:16.6.0-pre.61-kotlin-1.3.0’ compile ‘org.jetbrains:kotlin-react-dom:16.6.0-pre.61-kotlin-1.3.0’
import kotlinx.html.InputType
import kotlinx.html.js.*
import org.w3c.dom.HTMLSelectElement
import org.w3c.dom.events.Event
import react.*
import react.dom.*
interface SelectTestState : RState {
var value: String
}
class SelectTest : RComponent<RProps, SelectTestState>() {
override fun SelectTestState.init() {
value = "coconut"
}
private fun handleChange(event: Event) {
val target = event.target as HTMLSelectElement
setState {
value = target.value
}
}
private fun handleSubmit(event: Event) {
println("Your favorite flavor is: ${state.value}")
event.preventDefault()
}
override fun RBuilder.render() {
form {
attrs.onSubmitFunction = {
handleSubmit(it)
}
label {
+"Pick your favorite flavor:"
select {
attrs.value = state.value
attrs.onChangeFunction = {
handleChange(it)
}
option {
attrs.value = "grapefruit"
+"grapefruit"
}
option {
attrs.value = "lime"
+"lime"
}
option {
attrs.value = "coconut"
+"coconut"
}
option {
attrs.value = "mango"
+"mango"
}
}
}
input {
attrs.type = InputType.submit
attrs.value = "Submit"
}
}
}
}
fun RBuilder.selectTest() = child(SelectTest::class) {}
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:8 (1 by maintainers)
Top Results From Across the Web
Forms - React
The select Tag. In HTML, <select> creates a drop-down list. For example, this HTML creates a drop-down list of flavors ...
Read more >reactjs - HTML Select Input Tag bringing error ... - Stack Overflow
It's basically a warning that encourages you to change your code from doing <option selected> to doing <select defaultValue="theValue"> or ...
Read more >A complete guide to React refs - LogRocket Blog
Learn how to use React refs, and why it's important to use them only when React can't handle a function call through its...
Read more >How To Customize React Components with Props
In this tutorial, you'll create custom components by passing props to your component. Props are arguments that you provide to a JSX element....
Read more >Working With ReactJS in WebStorm: Coding Assistance
In JSX tags, the IDE provides coding assistance for React-specific attributes such ... Here's an example from official React documentation: ...
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
Same here. Problems seems to be the setter in RDOMBuilder that always converts the value into a set:
I’m seeing the same thing with the following select:
I discovered this on version:
org.jetbrains:kotlin-react:16.6.0-pre.62-kotlin-1.3.0
org.jetbrains:kotlin-react-dom:16.6.0-pre.62-kotlin-1.3.0
It is also reproing for me on the latest versions:
org.jetbrains:kotlin-react:16.6.0-pre.69-kotlin-1.3.21
org.jetbrains:kotlin-react-dom:16.6.0-pre.69-kotlin-1.3.21