SearchTopAppBar

fun SearchTopAppBar(navigationIcon: ImageVector?, onNavigationIconClick: () -> Unit, showSearch: Boolean, searchQuery: String, onSearchQueryChange: (String) -> Unit, modifier: Modifier = Modifier, title: String = stringResource(id = CommonR.string.app_name), searchPlaceholder: String = stringResource(id = R.string.search), clearSearchContentDescription: String = stringResource(id = R.string.clear_search), centerTitle: Boolean = false, onSearch: (String) -> Unit? = null, filters: @Composable RowScope.() -> Unit = {}, actions: @Composable RowScope.() -> Unit = {}, onSupportClick: () -> Unit? = null, showSupportAction: Boolean = true, scrollBehavior: TopAppBarScrollBehavior? = null, windowInsets: WindowInsets = TopAppBarDefaults.windowInsets)(source)

A top app bar whose title slot swaps for a search field.

It is the MainTopAppBar of a screen that filters what is behind it: the same navigation icon, overflow action and destination actions, with the title crossfading into a GeneralTextFieldStyle.Search field while showSearch is true. The bar owns only that swap; the query and whether search is showing stay with the caller, so the same state drives the bar and the filtering underneath it.

Both states share one fixed-height slot and fade in place, so neither the title nor the placeholder moves while they swap. The title animates between values the way MainTopAppBar's does. The state the bar is first composed in is shown without an entrance, so a screen that opens straight into search does not flash its title, and the title still appears the first time search is turned off.

Filters are optional and go in filters, the row that sits inside the field, to the left of the clear button. SearchFilterAction is the ready-made toggle for one: it renders tonally while the filter is applied and as text while it is not, so an active sort or filter reads as active without a second surface. Actions that belong to the bar rather than to the query go in actions.

The Support overflow item is rendered only when the host supplies onSupportClick, matching MainTopAppBar, so this module stays free of any dependency on a support feature.

Parameters

title

Shown while showSearch is false; defaults to the host's app name.

navigationIcon

The ImageVector drawn as the navigation icon, or null for none.

onNavigationIconClick

Invoked when the navigation icon is clicked.

showSearch

Whether the search field replaces the title.

searchQuery

The current query.

onSearchQueryChange

Receives every edit, including the clear button's empty string.

modifier

The Modifier applied to the bar.

searchPlaceholder

Shown while the field is empty.

clearSearchContentDescription

Accessibility description of the clear button.

centerTitle

Whether the title is centered; the search field always fills the slot.

onSearch

Called when the keyboard's search action is used. A filter that already applied itself as the query was typed needs nothing here.

filters

Row placed inside the search field, before the clear button. Empty by default.

actions

Destination-owned app bar actions, drawn after the Support overflow.

onSupportClick

Host callback that opens Support. The overflow action is hidden when it is null, so hosts without a support surface get no dead menu entry.

showSupportAction

Whether to render the Support overflow action when a callback exists.

scrollBehavior

Applied to the bar, defining how it behaves as content is scrolled.

windowInsets

Insets the bar consumes.