Search is an interactive interface element that allows users to query and retrieve specific data.

TypeResource
DesignFigma
MobileMobile Storybook
CodeGitlab

Search Preview

Usage

To implement search, you can use this tag SearchInput in the Kotlin file.

    import id.co.biofarma.binduiandroid.components.search.Search
    var query by remember { mutableStateOf(
        TextFieldValue(text="A", selection = TextRange.Zero)) }
    val suggestions = listOf("Apple", "Banana", "Cherry", "Grape", "Durian", "Vet en hard")
    var isShowSuggestion by remember { mutableStateOf(true) }
 
    SearchInput(
        query = query,
        placeholder = "Search here...",
        size = "sm",
        onQueryChange = {
            newText ->
            query = if (disabled) TextFieldValue(text=value, selection = TextRange(value.length)) else newText
            isShowSuggestion = suggestions.any { it.contains(newText.text, ignoreCase = true) } && newText.text.isNotEmpty()
        },
        endIcon = null,
        isShowSuggestion = isShowSuggestion,
        suggestions = suggestions.filter { it.contains(query.text, ignoreCase = true) },
        onItemSelected = {
            query = TextFieldValue(it, selection = TextRange(it.length))
            isShowSuggestion = false
        },
        onClearText = {
            query = TextFieldValue("")
            isShowSuggestion = false
        },
        disabled = false,
    )

Example

Size

Set the size prop to sm, md or lg.

Search Size

Disabled

Set the disabled prop to true if you would like to set it disabled.

Search Disabled

Suggestion items are fetched from your array list in suggestion props. Pass the isShowSuggestion prop to true or false. Set true if you would like to display the suggestion on search.

Search Suggestion

To close the suggestion when you’ve selected an item, you could set isShowSuggestion to false in onItemSelected props.

Search onItemSelected

Search with End Icon (optional)

Pass the endIcon prop with Icon.

Search End Icon


Props

PropsRequiredDefaultTypedescription
idfalse-stringA unique identifier for the component
queryfalse-TextFieldValueControlled input value that represents the current text in the search input field
sizefalse-sm, md, lgThe search input box size
placeholdertrue-stringThe search input placeholder text.
onQueryChangefalse-(TextFieldValue) -> UnitCallback function invoked when the text input value changes.
endIconfalse-ComposeableA composable function that describes the icon on the right search input.
isShowSuggestionfalsefalsetrue falseDisplay suggestions list
suggestionsfalse[]ArrayList<String>List of suggestions that appear when typing
onItemSelectedfalse-(String) -> UnitCallback function invoked when a suggestion item is selected
onClearTextfalse-() -> UnitCallback funtion to remove any value text selected
disabledfalsefalsetrue falseIf true, the search input will be set to disabled
modifierfalse-modifierTo decorate or add behavior to Compose UI elements
BIND © Biofarma Innovate Next-level Design .