I'm having an issue where my row's height is too t...
# compose
n
I'm having an issue where my row's height is too tall when using intrinsic height when there's a small button inside Is there any way to get my row to shrink to the height of the content? Snippet in thread
Copy code
CompositionLocalProvider(LocalMinimumInteractiveComponentEnforcement provides false) {
        Row(
            modifier = Modifier
                .height(IntrinsicSize.Max)
                .border(2.dp, Color.Red)
        ) {
            Text(
                modifier = Modifier.weight(1f),
                text = "Text"
            )

            Button(
                modifier = Modifier.heightIn(min = 1.dp),
                contentPadding = PaddingValues(0.dp),
                onClick = {}
            ) {
                Text(text = "Button")
            }

            // Must fill max height without growing the row
            Box(
                modifier = Modifier
                    .background(Color.Cyan)
                    .width(16.dp)
                    .fillMaxHeight()
            )
        }
    }
If I either • Remove the box and intrinsic height • Remove the button It will display as I intend, but it seems like the combo of button + intrinsic row height causes this
s
If you replaced "Button" with something simpler like a Box do you see the same result? Asking because material buttons may have some hardcoding internally regarding how much space they take according to the material design system
n
Thanks for taking a look, yes replacing button works, but if it's possible I'd prefer use the inbuilt button I'm pretty sure it's the
defaultMinSize
inside Button causing it (I can copy-paste the Button implementation and remove defaultMinSize to resolve it) Do you know of a solution without doing this though? It works fine when I don't use intrinsic height, and I don't understand why
s
There's nothing "in-built" about
Button
in particular. It's a button which follows the material/material3 specs, and those specs need to adhere to whatever their designers decided. In this case it looks like they decided it must have some default min size. If your app does is not built using the material design system then you must make your own component. You will notice this more and more if you continue using material but you have your own custom needs. Those components are not really written in a way which makes such customization easy.
n
Thanks. I will make my own implementation if it's needed to solve this My understanding is
defaultMinSize
could be overridden with
Modifier.heightIn(minSize = ...)
, but I am using this already so its behaviour seems unexpected (to me). Do you know why heightIn isn't overriding defaultMinSize in this situation?
s
Yeah I also believe it should be overridable this way, but I am not sure tbh. I've long stopped using material components because I couldn't be bothered always trying to look for such workarounds. Instead you can copy-paste their code and start from there, or even start from scratch. Then you get no such surprises, you control it all.
n
🙂 thanks