UX4G Logo
Components

Search Field

Search bar with instant autocomplete suggestions, voice search trigger, submit action button, and validation states

The UX4G Search Field component provides an intuitive search bar for discovering government welfare schemes, tracking application statuses, navigating civil service portals, and filtering dense data listings.

Key Capabilities

  • Instant Autocomplete & Dropdown Suggestions: Real-time suggestion popup with customizable matching algorithms (Contains, StartsWith, StartsWithPerTerm) and highlighting ("Searching for '...'").
  • Search Variants: Standard input field (BasicSearch), search bar with integrated CTA button (SearchWithSubmit), and predictive search (Autocomplete).
  • Interactive Controls: Built-in voice search trigger (showVoiceIcon), dynamic one-tap clear button (showClearIcon), and inline progress loader (isLoading).
  • Validation & Size Support: Contextual statuses (Default, Success, Warning, Error) with captions and 4 size tiers (Small, Medium, Large, XL).

Import from com.ux4g.designsystemv1.components.searchfield.*.


Interactive Previews

1. Default State with Submit Button

Search bar with label, placeholder, integrated voice search, clear button, and filled search submit CTA.

Ux4gSearchField (Search with Submit Button)Jetpack Compose
UX4G Default Search Field with Submit Button

2. Expanded State with Autocomplete Suggestions

Search bar with entered query and an expanded dropdown list of matching suggestion items.

Ux4gSearchField (Expanded Autocomplete Suggestions)Jetpack Compose
UX4G Expanded Autocomplete Search Field

Kotlin Usage

1. Basic Search with Voice and Clear Handlers

CitizenPortalSearch.kt
import androidx.compose.foundation.layout.*
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.ux4g.designsystemv1.components.searchfield.Ux4gSearchField
import com.ux4g.designsystemv1.components.searchfield.Ux4gSearchFieldSize

@Composable
fun CitizenPortalSearchSection() {
    var searchQuery by remember { mutableStateOf("") }

    Column(
        modifier = Modifier.padding(16.dp),
        verticalArrangement = Arrangement.spacedBy(8.dp)
    ) {
        Ux4gSearchField(
            value = searchQuery,
            onValueChange = { searchQuery = it },
            label = "Universal Search",
            placeholder = "Search schemes, certificates, or grievance status...",
            size = Ux4gSearchFieldSize.Medium,
            showVoiceIcon = true,
            showClearIcon = true,
            onVoiceClick = {
                // Launch Android SpeechRecognizer Intent
            },
            onClearClick = {
                searchQuery = ""
            }
        )
    }
}

2. Autocomplete Scheme Search with Submit Button

SchemeAutocompleteSearch.kt
import androidx.compose.foundation.layout.*
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.ux4g.designsystemv1.components.searchfield.*

@Composable
fun SchemeSearchWithSuggestions(
    onSchemeSelected: (String) -> Unit
) {
    var searchQuery by remember { mutableStateOf("") }
    val schemeList = remember {
        listOf(
            "Pradhan Mantri Awas Yojana (PMAY)",
            "Pradhan Mantri Jan Dhan Yojana (PMJDY)",
            "Ayushman Bharat - PMJAY",
            "Kisan Samman Nidhi (PM-KISAN)",
            "National Social Assistance Programme"
        )
    }

    Ux4gSearchField(
        value = searchQuery,
        onValueChange = { searchQuery = it },
        variant = Ux4gSearchFieldVariant.Autocomplete,
        filterType = Ux4gSearchFilterType.Contains,
        label = "Government Welfare Schemes",
        placeholder = "Type scheme name...",
        options = schemeList,
        onOptionSelected = { selectedScheme ->
            searchQuery = selectedScheme
            onSchemeSelected(selectedScheme)
        },
        onSubmitClick = { query ->
            onSchemeSelected(query)
        }
    )
}

Parameters

Ux4gSearchField Props

PropTypeDescriptionDefault
value *StringCurrent input text query.—
onValueChange *(String) -> UnitCallback invoked as text changes in the search field.—
modifierModifierCompose modifier applied to the outer layout container.Modifier
filterTypeUx4gSearchFilterTypeMatching algorithm (Contains, StartsWith, StartsWithPerTerm).Ux4gSearchFilterType.Contains
variantUx4gSearchFieldVariantVisual variant (BasicSearch, SearchWithSubmit, Autocomplete).Ux4gSearchFieldVariant.BasicSearch
sizeUx4gSearchFieldSizePredefined height size (Small, Medium, Large, XL).Ux4gSearchFieldSize.Medium
statusUx4gSearchFieldStatusVisual validation status (Default, Success, Warning, Error).Ux4gSearchFieldStatus.Default
buttonStyleUx4gSearchFieldButtonStyleSubmit button visual style (Filled, Tonal).Ux4gSearchFieldButtonStyle.Filled
labelString?Primary label text displayed above the search bar.null
placeholderString?Placeholder text shown when input is empty.null
captionString?Helper or error caption text displayed below the field.null
optionsList<String>List of selectable suggestion items for autocomplete popup.emptyList()
showVoiceIconBooleanWhether to display the trailing voice microphone icon.true
showClearIconBooleanWhether to display the clear X icon when text is entered.true
isLoadingBooleanShows an inline spinner indicator while queries are loading.false
onVoiceClick(() -> Unit)?Callback triggered when the voice search microphone icon is clicked.null
onClearClick(() -> Unit)?Callback triggered when the clear X icon is clicked.null
onSubmitClick((String) -> Unit)?Callback fired when the submit button is clicked or Enter is pressed.null
onOptionSelected((String) -> Unit)?Callback triggered when a user taps a dropdown suggestion item.null
enabledBooleanControls interactive touch state and disabled visual appearance.true
readOnlyBooleanPrevents keyboard edits while retaining copy/selection interaction.false
placeholderStyleTextStyle?Custom typography style override for placeholder text.null
dropdownMinHeightDpMinimum height for the autocomplete suggestions popup.0.dp
dropdownMaxHeightDpMaximum constraint height for the autocomplete suggestions popup.350.dp

Ux4gSearchFieldVariant Reference

VariantDescription
BasicSearchStandard single-row search field with trailing voice and clear icons.
SearchWithSubmitSearch field attached to a right-aligned dedicated search submit button.
AutocompleteSearch field that triggers a floating popup with filtered suggestion options.

Ux4gSearchFieldSize Reference

SizeHeight (Dp)Typical Usage
Small32.dpCompact table filters, toolbar search, and high-density headers
Medium40.dpStandard application form and search bars
Large48.dpPrimary screen search bars and mobile top headers
XL56.dpProminent home landing page hero search inputs

Ux4gSearchFilterType Reference

Filter TypeMatching Behavior
ContainsMatches any option containing the search substring anywhere in the label.
StartsWithMatches options starting with the search query from the first character.
StartsWithPerTermTokenizes query words and matches options where each term matches word starts.

Ux4gSearchFieldStatus Reference

StatusBorder / Text ColorContext
DefaultUx4gColors.neutral300 / primaryNormal idle or focused search field
SuccessUx4gColors.green600Successfully verified search parameter
WarningUx4gColors.secondary600Cautionary or limited results query
ErrorUx4gTheme.colorScheme.errorInvalid query format or failed search parameter

On this page