Hi :slightly_smiling_face: I have a strange issue ...
# compose
a
Hi 🙂 I have a strange issue with
DropdownMenu
and I don't know if it's me doing something wrong. I want the `DropdownMenuItem`s to contain an icon and text. It however seems like the width of the items are based on the text solely and not the combined width. I have this implementation as an example (in the
actions
part of a
TopAppBar
):
Copy code
IconButton(onClick = { showMenu = !showMenu }) {
    Icon(<http://Icons.Default.Menu|Icons.Default.Menu>, contentDescription = null)
}

DropdownMenu(
    expanded = showMenu,
    onDismissRequest = { showMenu = false }
) {
    DropdownMenuItem(
        onClick = { }
    ) {
        Icon(Icons.Default.ThumbUp, contentDescription = null)
        Text("This is a line", maxLines = 1)
    }
    DropdownMenuItem(
        onClick = { }
    ) {
        Icon(Icons.Default.Clear, contentDescription = null)
        Text("This is another line", maxLines = 1)
    }
}
I've attached some Screenshots. The first is how it looks with the above implementation (see the second line is cut off). The second is how it looks without the icons - notice how the width of the box is exactly the same as the first. The third is how I want it to look in the end (I achieved this by setting a static with on one of the `Text`s to 170 dp). Does anyone know what I'm doing wrong - or could it be a bug?
👀 1
1
f
What happens without maxLines?
a
Thanks for asking 🙂 It splits the text into two lines - and for a long word, it splits the word as well. I think it's the same case, it actually meassures the text as being the widest composable, but forgets to take into consideration there are others as well.
f
To test this theory, can you please show the same dropdown menu with an even longer text?
a
Sure 🙂 I've tried to make a short video where try to expand the text on the fly. Click the top one inserts a "a" and pressing the bottom inserts a whitespace. Don't know if that helps anything?
a
I believe it's a bug that the intrinsic size of the
Icon
is zero. Filed an issue: https://issuetracker.google.com/issues/198206454
a
Oh, that would make sense! Any way I can fix this locally?
a
For now you can explicitly specify the size of the icon. Since material icons are all 24dp, you can specify
Modifier.size(24.dp)
.
👍 4
a
Thanks a lot, it worked! 🙂
👍 2
s
I was facing the same issue, thanks for this thread 🙂
❤️ 1