So i have a wrapper function that styles a card. ...
# compose
m
So i have a wrapper function that styles a card. The issue i’m having is that if i pass a testTag through the modifier, and that modifier is passed along to the Card function i’m calling, i end up with two nodes with the same test tag:
Copy code
@Composable
fun MyCard(modifier: Modifier = Modifier, ...) {
    Card(modifier = modifier, ...) { ... }
}
z
That will only happen if you use the same modifier for multiple composables/layout nodes, which is generally a bad idea for many reasons. The code snippet you posted only applies it to one, but are you using it somewhere else in your actual code?
m
@Zach Klippenstein (he/him) [MOD] it’s going through multiple levels:
Copy code
@Composable
fun CLCard(
    modifier: Modifier = Modifier,
    size: CLCardSize = CLCardSize.MEDIUM,
    variant: CLCardVariant = CLCardVariant.FILL,
    tone: CLMaterialTone = CLMaterialTone.Material1,
    elevation: CLCardElevation = CLCardElevation.REST,
    content: @Composable BoxScope.() -> Unit
) {
    when (variant) {
        CLCardVariant.FILL ->
            CLCardFill(
                modifier = modifier,
                size = size,
                tone = tone,
                elevation = elevation,
                content = content
            )
inside of CLCardFill, we’re then passing it to the Card function:
Copy code
@Composable
internal fun CLCardFill(
    modifier: Modifier = Modifier,
    size: CLCardSize = CLCardSize.MEDIUM,
    tone: CLMaterialTone = CLMaterialTone.Material1,
    elevation: CLCardElevation = CLCardElevation.REST,
    content: @Composable BoxScope.() -> Unit
) {
    Card(
        modifier = modifier.semantics {
            this.materialTone = tone
            this.cardVariant = CLCardVariant.FILL
            this.cardElevation = elevation
            this.cardSize = size
        },
Copy code
|-Node #6 at (l=16.0, t=71.0, r=304.0, b=210.0)px, Tag: 'foobar'
         MaterialTone = 'Material2'
         CardVariant = 'STROKE'
         CardElevation = 'REST'
         CardSize = 'MEDIUM'
          |-Node #9 at (l=16.0, t=71.0, r=304.0, b=210.0)px, Tag: 'foobar'
i assume maybe because i’m applying semantic properties to the Card itself, so it’s creating a new instance of the modifier
I think i see the issue now. I have Box inside the Card where i forgot to capitalize Modifier
so the box has the same test tag
z
m
rubber duck