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

typethe type of element that is anchoring the menu. See ExposedDropdownMenuAnchorType.
enabledwhether 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

matchAnchorWidthwhether 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

expandedwhether the menu is expanded
onDismissRequestcalled when the user requests to dismiss the menu, such as by tapping outside the menu's bounds
modifierthe Modifier to be applied to this menu
scrollStatea ScrollState used by the menu's content for items vertical scrolling
matchAnchorWidthwhether the menu's width should be forcefully constrained to match the width of the text field to which it's attached.
shapethe shape of the menu
containerColorthe container color of the menu
tonalElevationwhen 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.
shadowElevationthe elevation for the shadow below the menu
borderthe border to draw around the container of the menu. Pass null for no border.
contentthe 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,
        )