Close the keyboard after a search

Clearing focus alone left Samsung's keyboard up over the results after the
search key or a suggestion. The keyboard is now hidden first, while the field
still has its input session, then focus is cleared.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Yuriy PanovandClaude Opus 5.5 committed 2026-10-23 16:27:59 +06:00
1 parent 329686ab02
commit 8b7778d95c
1 file changed
+10 -2
@@ -28,6 +28,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.clip
import androidx.compose.ui.platform.LocalFocusManager import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.text.style.TextOverflow
@@ -67,6 +68,13 @@ fun SearchScreen(state: AppState) {
val search = state.search val search = state.search
val space = MusyxTheme.space val space = MusyxTheme.space
val focus = LocalFocusManager.current val focus = LocalFocusManager.current
val keyboard = LocalSoftwareKeyboardController.current
// Losing focus alone leaves some keyboards (Samsung's) up over the results.
val done = {
// Hidden while the field still has its input session; after, there's nothing to hide.
keyboard?.hide()
focus.clearFocus()
}
PageColumn { PageColumn {
item(key = "field") { item(key = "field") {
OutlinedTextField( OutlinedTextField(
@@ -81,7 +89,7 @@ fun SearchScreen(state: AppState) {
shape = RoundedCornerShape(MusyxTheme.radius.pill), shape = RoundedCornerShape(MusyxTheme.radius.pill),
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Search), keyboardOptions = KeyboardOptions(imeAction = ImeAction.Search),
keyboardActions = KeyboardActions(onSearch = { keyboardActions = KeyboardActions(onSearch = {
focus.clearFocus() done()
search.submit() search.submit()
}), }),
modifier = Modifier.fillMaxWidth().padding(horizontal = space.gutter), modifier = Modifier.fillMaxWidth().padding(horizontal = space.gutter),
@@ -92,7 +100,7 @@ fun SearchScreen(state: AppState) {
Modifier Modifier
.fillMaxWidth() .fillMaxWidth()
.clickable { .clickable {
focus.clearFocus() done()
search.pick(s) search.pick(s)
} }
.padding(horizontal = space.gutter + 4.dp, vertical = 10.dp), .padding(horizontal = space.gutter + 4.dp, vertical = 10.dp),