androidx.compose.material3

FilterChip

Composable function

One of the chip types. It works like AssistChip. Only the parameters that differ are described here.

A chip that turns on and off, like a filter in a search.

Filter chips that toggle
Filter chips that toggle
var vegan by remember { mutableStateOf(true) }
var spicy by remember { mutableStateOf(false) }
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
    FilterChip(
        selected = vegan,
        onClick = { vegan = !vegan },
        label = { Text("Vegan") },
        leadingIcon = if (vegan) {
            { Icon(Icons.Filled.Done, null, Modifier.size(FilterChipDefaults.IconSize)) }
        } else null,
    )
    FilterChip(selected = spicy, onClick = { spicy = !spicy }, label = { Text("Spicy") })
}

Basic

Takes one shape.

@Composable
fun FilterChip(
    selected: Boolean,
    onClick: () -> Unit,
    label: @Composable () -> Unit,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    leadingIcon: @Composable (() -> Unit)? = null,
    trailingIcon: @Composable (() -> Unit)? = null,
    shape: Shape = FilterChipDefaults.shape,
    colors: SelectableChipColors = FilterChipDefaults.filterChipColors(),
    elevation: SelectableChipElevation? = FilterChipDefaults.filterChipElevation(),
    border: BorderStroke? = FilterChipDefaults.filterChipBorder(enabled, selected),
    horizontalArrangement: Arrangement.Horizontal = FilterChipDefaults.horizontalArrangement(),
    contentPadding: PaddingValues = FilterChipDefaults.ContentPadding,
    interactionSource: MutableInteractionSource? = null,
)

selected: BooleanRequired

Whether the chip is selected. Only on FilterChip and InputChip. You keep this state yourself.

Filter chips that toggle
Filter chips that toggle
var vegan by remember { mutableStateOf(true) }
var spicy by remember { mutableStateOf(false) }
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
    FilterChip(
        selected = vegan,
        onClick = { vegan = !vegan },
        label = { Text("Vegan") },
        leadingIcon = if (vegan) {
            { Icon(Icons.Filled.Done, null, Modifier.size(FilterChipDefaults.IconSize)) }
        } else null,
    )
    FilterChip(selected = spicy, onClick = { spicy = !spicy }, label = { Text("Spicy") })
}

colors: SelectableChipColorsOptional

Default: FilterChipDefaults.filterChipColors()

Sets the container, label and icon colors. Make one with the chip's defaults object, for example FilterChipDefaults.filterChipColors.

elevation: SelectableChipElevation?Optional

Default: FilterChipDefaults.filterChipElevation()

Sets the shadow height. Default: flat. Use the elevated… functions in the defaults object for a raised chip.

Defaults that differ from AssistChip:

Same as in AssistChip: onClick, label, modifier, enabled, leadingIcon, trailingIcon, shape, border, horizontalArrangement, contentPadding, interactionSource.

Expressive

Takes shapes: separate shapes for rest, selected and pressed.

@Composable
fun FilterChip(
    selected: Boolean,
    onClick: () -> Unit,
    label: @Composable () -> Unit,
    shapes: ChipShapes,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    leadingIcon: @Composable (() -> Unit)? = null,
    trailingIcon: @Composable (() -> Unit)? = null,
    colors: SelectableChipColors = FilterChipDefaults.tonalFilterChipColors(),
    elevation: SelectableChipElevation? = FilterChipDefaults.filterChipElevation(),
    border: BorderStroke? = FilterChipDefaults.filterChipBorder(enabled, selected),
    horizontalArrangement: Arrangement.Horizontal = FilterChipDefaults.horizontalArrangement(leadingIcon != null, trailingIcon != null),
    contentPadding: PaddingValues = FilterChipDefaults.ContentPadding,
    interactionSource: MutableInteractionSource? = null,
)

shapes: ChipShapesRequiredSince 1.12

Sets shapes for rest, selected and pressed. Takes a ChipShapes.

Defaults that differ from AssistChip:

Same as above: selected, colors, elevation.

Same as in AssistChip: onClick, label, modifier, enabled, leadingIcon, trailingIcon, border, horizontalArrangement, contentPadding, interactionSource.

Chip types

See also