DropdownMenu
Material Design dropdown menu.
Menus display a list of choices on a temporary surface. They appear when users interact with a button, action, or other control.
A DropdownMenu behaves similarly to a Popup, and will use the position of the parent layout to position itself on screen. Commonly a DropdownMenu will be placed in a Box with a sibling that will be used as the 'anchor'. Note that a DropdownMenu by itself will not take up any space in a layout, as the menu is displayed in a separate window, on top of other content.
The content of a DropdownMenu will typically be DropdownMenuItems, as well as custom content. Using DropdownMenuItems will result in a menu that matches the Material specification for menus. Also note that the content is placed inside a scrollable Column, so using a LazyColumn as the root layout inside content is unsupported.
onDismissRequest will be called when the menu should close - for example when there is a tap outside the menu, or when the back key is pressed.
DropdownMenu changes its positioning depending on the available space, always trying to be fully visible. Depending on layout direction, first it will try to align its start to the start of its parent, then its end to the end of its parent, and then to the edge of the window. Vertically, it will try to align its top to the bottom of its parent, then its bottom to top of its parent, and then to the edge of the window.
An offset can be provided to adjust the positioning of the menu for cases when the layout bounds of its parent do not coincide with its visual bounds.
Example usage:
Parameters
whether the menu is expanded or not
called when the user requests to dismiss the menu, such as by tapping outside the menu's bounds
Modifier to be applied to the menu's content
DpOffset from the original position of the menu. The offset respects the LayoutDirection, so the offset's x position will be added in LTR and subtracted in RTL.
a ScrollState to used by the menu's content for items vertical scrolling
PopupProperties for further customization of this popup's behavior
the shape of the menu
the container color of the menu
when containerColor is ColorScheme.surface, a translucent primary color overlay is applied on top of the container. A higher tonal elevation value will result in a darker color in light theme and lighter color in dark theme. See also: Surface.
the elevation for the shadow below the menu
the border to draw around the container of the menu. Pass null
for no border.
the content of this dropdown menu, typically a DropdownMenuItem