Skip to content

ChipTextField

Signature

@Composable
fun <T> ChipTextField(
state: ChipTextFieldState<T>,
onCreateChip: (String) -> T?,
modifier: Modifier = Modifier,
chipContent: (@Composable (T, onRemove: () -> Unit) -> Unit)? = null,
chipLabel: (T) -> String = { it.toString() },
chipLeadingIcon: (@Composable ChipScope<T>.() -> Unit)? = null,
chipTrailingIcon: (@Composable ChipScope<T>.() -> Unit)? = null,
onChipRemoved: ((T) -> Unit)? = null,
onQueryChanged: ((String) -> Unit)? = null,
suggestionContent: @Composable ((query: String, onSuggestionSelected: (T) -> Unit) -> Unit)? = null,
placeholder: @Composable (() -> Unit)? = null,
leadingIcon: @Composable (() -> Unit)? = null,
enabled: Boolean = true,
readOnly: Boolean = false,
delimiters: Set<Char> = ChipTextFieldDefaults.delimiters,
maxChips: Int = Int.MAX_VALUE,
colors: ChipTextFieldColors = ChipTextFieldDefaults.colors(),
shape: Shape = ChipTextFieldDefaults.shape,
)

Parameters

ParameterTypeDefaultDescription
stateChipTextFieldState<T>Manages the chip list. Create via rememberChipTextFieldState().
onCreateChip(String) -> T?Factory function. Return null to reject input.
modifierModifierModifierModifier for the outer container.
chipContent@Composable (T, () -> Unit)?nullFull custom chip rendering. Overrides chipLeadingIcon/chipTrailingIcon.
chipLabel(T) -> StringtoString()Extracts display label from chip data.
chipLeadingIcon@Composable ChipScope<T>.() -> Unit?nullLeading icon inside the default chip.
chipTrailingIcon@Composable ChipScope<T>.() -> Unit?nullTrailing icon. Defaults to close button when null.
onChipRemoved((T) -> Unit)?nullCallback when a chip is removed.
onQueryChanged((String) -> Unit)?nullFires when input text changes. Use for suggestion filtering.
suggestionContent@Composable ((String, (T) -> Unit) -> Unit)?nullSuggestion dropdown rendered below the field.
placeholder@Composable (() -> Unit)?nullShown when no chips and no text.
leadingIcon@Composable (() -> Unit)?nullIcon before all chips in the field.
enabledBooleantrueWhether the field is interactive.
readOnlyBooleanfalseDisplay chips without editing.
delimitersSet<Char>{',', '\n'}Characters that trigger chip creation.
maxChipsIntInt.MAX_VALUEMaximum number of chips. Input hides at limit.
colorsChipTextFieldColorsChipTextFieldDefaults.colors()Color configuration.
shapeShapeRoundedCornerShape(8.dp)Shape of the outer container.

Layout

ChipTextField uses FlowRow inside a Column:

Column
├── FlowRow
│ ├── [leadingIcon]
│ ├── Chip 1, Chip 2, ...
│ └── BasicTextField (input)
└── [suggestionContent] (when text is non-empty)

Chips wrap to the next line automatically. The input field takes remaining space with a minimum width of 80dp.