Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resizeable BasicTextField in Jetpack Compose

Is there a way to produce a resizeable BasicTextField in Jetpack Compose, so that its width would wrap text size when a user types in or deletes characters? They've solved a similar problem for flutter, but I didn't find out how to solve this for Compose. Flutter - how to make TextField width fit its text ("wrap content")

var text: String by rememberSaveable { mutableStateOf("") }
BasicTextField(
   value = text,
   onValueChange = {
       text = it
   },
   modifier = Modifier.wrapContentWidth()
)

unfortunately, wrapContentWidth() doesn't work here.

like image 666
Ivan Abramov Avatar asked Nov 25 '25 18:11

Ivan Abramov


1 Answers

Well, looks like width(IntrinsicSize.Min) solves this problem:

var text: String by rememberSaveable { mutableStateOf("") }
BasicTextField(
   value = text,
   onValueChange = {
       text = it
   },
   modifier = Modifier.width(IntrinsicSize.Min)
)
like image 124
Ivan Abramov Avatar answered Nov 27 '25 07:11

Ivan Abramov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!