From e08df3b871e4b9265565c9ff88f3f858b7c79ca5 Mon Sep 17 00:00:00 2001 From: dankito Date: Mon, 26 Aug 2024 01:53:06 +0200 Subject: [PATCH] Fixed focusing next focusable element after selecting an item --- .../codinux/banking/ui/forms/AutocompleteTextField.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/forms/AutocompleteTextField.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/forms/AutocompleteTextField.kt index 431f6d1..f439fb1 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/forms/AutocompleteTextField.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/forms/AutocompleteTextField.kt @@ -13,9 +13,7 @@ import androidx.compose.material.icons.filled.Close import androidx.compose.runtime.Composable import androidx.compose.runtime.* import androidx.compose.ui.Modifier -import androidx.compose.ui.focus.FocusDirection -import androidx.compose.ui.focus.FocusRequester -import androidx.compose.ui.focus.focusRequester +import androidx.compose.ui.focus.* import androidx.compose.ui.geometry.Size import androidx.compose.ui.layout.onGloballyPositioned import androidx.compose.ui.platform.LocalDensity @@ -50,6 +48,7 @@ fun AutocompleteTextField( Box(Modifier.fillMaxWidth()) { OutlinedTextField( value = searchQuery, + singleLine = true, onValueChange = { query -> searchQuery = query onValueChange(null) @@ -88,7 +87,8 @@ fun AutocompleteTextField( suggestions = emptyList() expanded = false onValueChange(null) - } + textFieldFocus.requestFocus() + }.focusProperties { canFocus = false } ) } }, @@ -113,6 +113,8 @@ fun AutocompleteTextField( searchQuery = it.invoke(item) } expanded = false + + textFieldFocus.freeFocus() focusManager.moveFocus(FocusDirection.Down) } ) {