Jetpack Compose - where are the selectable card overloads?

567 Views Asked by At

I am using the androidx.compose.material3:material3:1.0.0-beta03.

The Javadoc of the simplest card (in the CardKt.kt file) says

This Card does not handle input events - see the other Card overloads if you want a clickable or selectable Card.

I do find the card with onClick, however I do not see a card which is selectable. Where is the mentioned overload?

1

There are 1 best solutions below

1
Gabriele Mariotti On

Currently the M3 Card doesn't have a selected parameter.
You can use something like:

var selected by remember { mutableStateOf(false) }
val interactionSource = remember { MutableInteractionSource() }

Card(
    modifier = Modifier
        .selectable(
            selected = selected,
            interactionSource = interactionSource,
            indication = rememberRipple(),
            enabled = enabled,
            onClick = { /* do something */ }
        )
){
    //card content...
}