Refactor: Introduce isInputFieldEmpty for clarity in SearchBarWithAutoCompletion

This commit is contained in:
Nebojsa Vuksic 2025-08-01 11:30:33 +02:00
parent 2eb729d331
commit 7996e74e24

View File

@ -44,6 +44,7 @@ internal fun <T> SearchBarWithAutoCompletion(
val focusRequester = remember { FocusRequester() } val focusRequester = remember { FocusRequester() }
val popupController = remember { CompletionPopupController(searchAutoCompletionItemProvider) } val popupController = remember { CompletionPopupController(searchAutoCompletionItemProvider) }
val isInputFieldEmpty by remember { derivedStateOf { textFieldState.text.isBlank() } }
LaunchedEffect(Unit) { LaunchedEffect(Unit) {
snapshotFlow { textFieldState.text.toString() } snapshotFlow { textFieldState.text.toString() }
@ -71,7 +72,7 @@ internal fun <T> SearchBarWithAutoCompletion(
Icon(AllIconsKeys.Actions.Find, contentDescription = null, Modifier.padding(end = 8.dp)) Icon(AllIconsKeys.Actions.Find, contentDescription = null, Modifier.padding(end = 8.dp))
}, },
trailingIcon = { trailingIcon = {
if (textFieldState.text.isNotBlank()) { if (!isInputFieldEmpty) {
CloseIconButton { CloseIconButton {
onClear() onClear()
textFieldState.setTextAndPlaceCursorAtEnd("") textFieldState.setTextAndPlaceCursorAtEnd("")