Is there any way to make `DropDownMenu` work like ...
# compose
a
Is there any way to make
DropDownMenu
work like
TextInputLayout
with
Spinner
? Like so?
y
Yup, you can use
DropdownMenu
, it takes a
toggle
composable where you can put anything (your
TextInputLayout
equivalent here), and a content composable where you can put a list of
DropdownMenuItem
(or whatever) for the drop down content
Copy code
var isOpen by remember { mutableStateOf(false) }
    DropdownMenu(
        toggle = {
           // Implement your toggle
        },
        expanded = isOpen,
        onDismissRequest = { isOpen = false }
    ) {
        items.forEach {
            DropdownMenuItem(
                onClick = {
                    // Do stuff
                    isOpen = false
                }
            ) {
                Text("option")
            }
        }
    }
👍 2
You might want to wrap the item inside the
forEach
into a
key
block, not sure about that part
a
the dropdown seems to always appear in the bottom left side of the set toggle though and the size of the dropdown menu items are larger than that of the toggle.. any tips on that?
m
Check the source code of the dropdownmenu position provider. The code is quite tiny, you could try to reimplement it
y
Yup, I've had issues also with the position of the drop down, it was super weird, didn't have time to dig further.
It could be a bug that should be mentionned to the team
a
@manueldidonna thats is true. But I was looking at the existing ones first before doing just that coz maybe Im missing something someone else already figured out.
@Yann Badoual Thank you very much for the inputs. Its seems to me that dropdownmenu wasnt designed for this usecase yet thats why I asked. hmmm... there seems to be no exact way to properly position the dropdown atleast based on how i looked around. Ill try and dig deeper.
m
`Spinner`s are planned and will be added
👍 1
In the meantime, yep, you could reimplement your own starting from the
DropdowMenu
implementation and tweaking the positioning and the layout
a
@Mihai Popa Awesome! Thank you very much for the info :D
m
It's unfortunate you would currently have to copy-paste all(?) the code for
DropdownMenu
as there is no intermediate API that allows changing the positioning
👍 1
No problem 🙂
❤️ 1
a
Its fine doing all the copy pasting forces me to learn how it works anyway.. so its probably still a win :)
y
Wouldn't it be possible to avoid copy-paste everything, and use a translation modifier on the content? Might have to do some maths to get it right, be should be possible no?
Since nothing is clipped by default on compose
a
Not really sure yet what to do.. didnt have much time to play around it yet.
m
Translation will not work, because the menu content is displayed in a separate window