Skip to main content

CamoSearchField

A search field: the search icon, the keyboard's Search action (Enter on desktop and web) calling onSearch, and a "Clear search" button while there's text, which clears and keeps focus. Esc clears too. leading replaces the search icon (a back button when a search is open); trailing adds e.g. a mic. Debouncing is the app's: the field reports every change. With autoFocus the field takes focus when it first appears (a search that opens on its own, such as the command palette's).

API​

public fun CamoSearchField(
query: String,
onQueryChange: (String) -> Unit,
onSearch: (String) -> Unit,
modifier: Modifier = Modifier,
placeholder: String = "Search",
leading: (@Composable () -> Unit)? = null,
trailing: (@Composable () -> Unit)? = null,
enabled: Boolean = true,
onFocusChanged: ((Boolean) -> Unit)? = null,
interactionSource: MutableInteractionSource? = null,
autoFocus: Boolean = false,
)
NameTypeDefault
queryStringrequired
onQueryChange(String) -> Unitrequired
onSearch(String) -> Unitrequired
modifierModifierModifier
placeholderString"Search"
leading(@Composable () -> Unit)?null
trailing(@Composable () -> Unit)?null
enabledBooleantrue
onFocusChanged((Boolean) -> Unit)?null
interactionSourceMutableInteractionSource?null
autoFocusBooleanfalse
Design notes

Why CamoSearchField works this way, its states and its edge cases: contributor docs.