Suggestions
Basic suggestions
Use suggestionContent to render a dropdown below the chip field. It receives the current query and a callback to select a suggestion:
val contacts = listOf( Contact("Alice", "alice@example.com"), Contact("Bob", "bob@example.com"), Contact("Carol", "carol@example.com"),)var filtered by remember { mutableStateOf(emptyList<Contact>()) }
ChipTextField( state = state, onCreateChip = { text -> contacts.find { it.email == text } ?: Contact(text, text) }, chipLabel = { it.name }, onQueryChanged = { query -> filtered = if (query.isBlank()) emptyList() else contacts.filter { it.name.contains(query, ignoreCase = true) } }, suggestionContent = { query, onSuggestionSelected -> filtered.forEach { contact -> Row( modifier = Modifier .fillMaxWidth() .clickable { onSuggestionSelected(contact) } .padding(12.dp), ) { Text(contact.name) Spacer(Modifier.width(8.dp)) Text(contact.email, color = Color.Gray) } } },)How it works
- User types →
onQueryChangedfires with the current text - You filter your data and store results in state
suggestionContentrenders below the field (only when text is non-empty)- User taps a suggestion →
onSuggestionSelectedadds it as a chip and clears the input
Gmail-style suggestions
The sample app includes a full Gmail Compose example with avatar initials and styled suggestion rows. See GmailComposeExample.kt.