Created
December 1, 2023 21:26
-
-
Save mirokolodii/d455ff64ca095f4937df2478f1ef0229 to your computer and use it in GitHub Desktop.
Search box with icons and edit text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun SearchBox( | |
onBackClick: () -> Unit, | |
) { | |
var searchText by remember { mutableStateOf("") } | |
Row( | |
horizontalArrangement = Arrangement.spaced(16.dp), | |
) { | |
Icon( | |
vector = Icons.Default.BackArrow, | |
modifier = Modifier.clickable { onBackClick() } | |
) | |
BasicTextField( | |
onValueChange = { value -> | |
searchText = value | |
onNewSearchText(value) | |
} | |
) | |
// Show 'clear text' icon only when text field has some value | |
if (!searchText.isBlank()) { | |
Icon( | |
vector = Icons.Default.BackArrow, | |
modifier = Modifier.clickable { searchText = "" } | |
) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment