androidx.compose.material3

ExpandedDockedSearchBarSince 1.9Experimental

Composable function

One of the search bar types. It works like SearchBar. Only the parameters that differ are described here.

The results open as a drop-down that is joined to the field.

Expanded as a drop-down under the fieldExpressive theme
Expanded as a drop-down under the field
val text = rememberTextFieldState()
val state = rememberSearchBarState(SearchBarValue.Expanded)
val field = @Composable {
    SearchBarDefaults.InputField(textFieldState = text, searchBarState = state, onSearch = {}, placeholder = { Text("Search photos") })
}
Box(Modifier.size(360.dp, 320.dp)) {
    SearchBar(state = state, inputField = field, modifier = Modifier.width(328.dp))
    ExpandedDockedSearchBar(state = state, inputField = field) { Suggestions() }
}

@Composable
fun Suggestions() {
    listOf("Beach", "Mountains", "Snow").forEach {
        ListItem(
            headlineContent = { Text(it) },
            leadingContent = { Icon(Icons.Filled.Search, null) },
            colors = ListItemDefaults.colors(containerColor = Color.Transparent),
        )
    }
}

ParametersExperimental

@Composable
fun ExpandedDockedSearchBar(
    state: SearchBarState,
    inputField: @Composable () -> Unit,
    modifier: Modifier = Modifier,
    shape: Shape = SearchBarDefaults.dockedShape,
    colors: SearchBarColors = SearchBarDefaults.colors(),
    tonalElevation: Dp = SearchBarDefaults.TonalElevation,
    shadowElevation: Dp = SearchBarDefaults.ShadowElevation,
    properties: PopupProperties = PopupProperties(focusable = true, clippingEnabled = false),
    content: @Composable ColumnScope.() -> Unit,
)

properties: PopupPropertiesOptional

Default: PopupProperties(focusable = true, clippingEnabled = false)

Window options for the expanded bar, like whether back closes it.

Defaults that differ from SearchBar:

Same as in SearchBar: state, inputField, modifier, shape, colors, tonalElevation, shadowElevation, content.

Search bar types

See also