Hi, Can someone help me on how to clear a textarea...
# compose-web
j
Hi, Can someone help me on how to clear a textarea in the following example.
d
Change the first line to
Copy code
var inputState = remember { mutableStateOf("") }
or, more idiomatically
Copy code
var inputState by remember { mutableStateOf("") }
// later
inputState = ""
j
@David Herman Thanks for your response. This is unfortunately not working as well. (I got the first line same as you proposed.
Same goes for the second variant I still get the initial problem even though here I can now assign directly.
Copy code
var inputState by remember { mutableStateOf("") }
// ...
// will not update TextArea
inputState = ""
o
I've changed your code a bit:
Copy code
val inputState = remember { mutableStateOf("") }
        TextArea(attrs = {
            value(inputState.value)
            onInput { event -> inputState.value = event.value }
            onKeyDown {
                if(it.key == "Enter" && it.shiftKey) { // changed `!it.shiftKey` to `it.shiftKey`
                 
                    inputState.value = ""
                    it.preventDefault() // added this
                }
            }
        })
now it clears the text area when pressing enter+shift
j
Thanks a a lot @Oleksandr Karpovich [JB] will try it out later. 🚀