Skip to content

ChipScope

Definition

@Immutable
class ChipScope<T>(
val chip: T,
val enabled: Boolean,
val colors: ChipTextFieldColors,
val onRemove: () -> Unit,
)

ChipScope is the receiver for chipLeadingIcon and chipTrailingIcon lambdas. It provides access to the chip data and state for conditional rendering.

Properties

PropertyTypeDescription
chipTThe chip data object. Use to read custom fields (e.g., chip.status, chip.color).
enabledBooleanWhether the chip is in an editable state.
colorsChipTextFieldColorsThe current color theme. Use colors.chipTextColor for consistent styling.
onRemove() -> UnitCall this to remove the chip. Essential for custom trailing close buttons.

Usage in chipLeadingIcon

chipLeadingIcon = {
// `this` is ChipScope<StatusItem>
Canvas(modifier = Modifier.size(10.dp)) {
drawCircle(color = chip.status.color)
}
}

Usage in chipTrailingIcon

chipTrailingIcon = {
Icon(
imageVector = Icons.Default.Close,
contentDescription = "Remove ${chip.label}",
modifier = Modifier
.size(16.dp)
.clickable(onClick = onRemove), // removes the chip
tint = colors.chipTextColor,
)
}