ExposedDropdownMenuBoxScope

Class
Common
@ExperimentalMaterial3Api
sealed class ExposedDropdownMenuBoxScope

Scope for ExposedDropdownMenuBox.

Functions

abstract fun Modifier.menuAnchor(
        type: ExposedDropdownMenuAnchorType,
        enabled: Boolean = true,
    ): Modifier

Modifier which should be applied to an element inside the ExposedDropdownMenuBoxScope, typically a text field or an icon within the text field. It's responsible for requesting focus, and if enabled, expanding/collapsing the menu on click and applying semantics.

Parameters

type the type of element that is anchoring the menu. See ExposedDropdownMenuAnchorType.
enabled whether controlling the menu via this anchor is enabled. When false, the component will not expand or collapse the menu in response to user input, and menu semantics will be invisible to accessibility services. Note that this value only controls interactions with the menu. It does not affect the enabled state of other kinds of interactions, such as TextField's enabled parameter.
abstract fun Modifier.exposedDropdownSize(matchAnchorWidth: Boolean = true): Modifier

Modifier which should be applied to a menu placed inside the ExposedDropdownMenuBoxScope. It will set constraints on the width and height of the menu so it will not overlap the text field or software keyboard.

ExposedDropdownMenu applies this modifier automatically, so this is only needed when using custom menu components.

Parameters

matchAnchorWidth whether the menu's width should be forcefully constrained to match the width of the text field to which it's attached.
@Composable
    fun ExposedDropdownMenu(
        expanded: Boolean,
        onDismissRequest: () -> Unit,
        modifier: Modifier = Modifier,
        scrollState: ScrollState = rememberScrollState(),
        matchAnchorWidth: Boolean = true,
        shape: Shape = MenuDefaults.shape,
        containerColor: Color = MenuDefaults.containerColor,
        tonalElevation: Dp = MenuDefaults.TonalElevation,
        shadowElevation: Dp = MenuDefaults.ShadowElevation,
        border: BorderStroke? = null,
        content: @Composable ColumnScope.() -> Unit,
    )

Popup which contains content for Exposed Dropdown Menu. Should be used inside the content of ExposedDropdownMenuBox.

Parameters

expanded whether the menu is expanded
onDismissRequest called when the user requests to dismiss the menu, such as by tapping outside the menu's bounds
modifier the Modifier to be applied to this menu
scrollState a ScrollState used by the menu's content for items vertical scrolling
matchAnchorWidth whether the menu's width should be forcefully constrained to match the width of the text field to which it's attached.
shape the shape of the menu
containerColor the container color of the menu
tonalElevation 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.
shadowElevation the elevation for the shadow below the menu
border the border to draw around the container of the menu. Pass null for no border.
content the content of the menu
fun Modifier.menuAnchor(): Modifier
@Composable
    fun ExposedDropdownMenu(
        expanded: Boolean,
        onDismissRequest: () -> Unit,
        modifier: Modifier = Modifier,
        scrollState: ScrollState = rememberScrollState(),
        focusable: Boolean = true,
        matchTextFieldWidth: Boolean = true,
        shape: Shape = MenuDefaults.shape,
        containerColor: Color = MenuDefaults.containerColor,
        tonalElevation: Dp = MenuDefaults.TonalElevation,
        shadowElevation: Dp = MenuDefaults.ShadowElevation,
        border: BorderStroke? = null,
        content: @Composable ColumnScope.() -> Unit,
    ) =
        ExposedDropdownMenu(
            expanded = expanded,
            onDismissRequest = onDismissRequest,
            modifier = modifier,
            scrollState = scrollState,
            matchAnchorWidth = matchTextFieldWidth,
            shape = shape,
            containerColor = containerColor,
            tonalElevation = tonalElevation,
            shadowElevation = shadowElevation,
            border = border,
            content = content,
        )
@Composable
    fun ExposedDropdownMenu(
        expanded: Boolean,
        onDismissRequest: () -> Unit,
        modifier: Modifier = Modifier,
        scrollState: ScrollState = rememberScrollState(),
        content: @Composable ColumnScope.() -> Unit,
    ) =
        ExposedDropdownMenu(
            expanded = expanded,
            onDismissRequest = onDismissRequest,
            modifier = modifier,
            matchTextFieldWidth = true,
            scrollState = scrollState,
            shape = MenuDefaults.shape,
            containerColor = MenuDefaults.containerColor,
            tonalElevation = MenuDefaults.TonalElevation,
            shadowElevation = MenuDefaults.ShadowElevation,
            border = null,
            content = content,
        )