2

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?

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
Florian Reisinger
  • 2,638
  • 4
  • 23
  • 34

1 Answers1

1

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...
}
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841