dokar3 / ChipTextField

Editable chip layout for Compose Multiplatform
Apache License 2.0
81 stars 3 forks source link

Focusing a non-empty ChipTextField #81

Closed jacksonh closed 11 months ago

jacksonh commented 1 year ago

Hello, I have a non-empty ChipTextField that I would like to auto focus when presented. I'm using code similar to this:

 val state = rememberChipTextFieldState(initialSelectedLabels.map {
    LabelChipView(it)
  })

  val focusRequester = remember { FocusRequester() }

  ChipTextField(
    state = state,
    modifier = Modifier .focusRequester(focusRequester)
  )

  LaunchedEffect(Unit) {
    focusRequester.requestFocus()
  }

When I run this the text is focused in the first chip in the text field. Is there a way to pass the focus to the very end of the text field?

dokar3 commented 1 year ago

Hi, currently, the focus handling is touch-based, so there is no way to programmatically focus on the last field. Will try to add a feature for this when I have time, thank you for your feedback.

jacksonh commented 1 year ago

Hey @dokar3 thanks. I'll see if I can figure out something too and will submit a PR if I get it working. Not the strongest with Android though, so doubt i get far.

dokar3 commented 1 year ago

@jacksonh Would be nice to see that, as I have very little time to focus on Android/Compose these days.

dokar3 commented 1 year ago

Hi, 0.4.7 is out with manual focus controlling, feel free to try. https://github.com/dokar3/ChipTextField/releases/tag/v0.4.7

jacksonh commented 1 year ago

@dokar3 nice, will test this out, thank you! (Sorry I haven't had much time lately too)