Skip to content

SearchField ​

A filled search input with a leading magnifier and a trailing clear button that appears only when a value is present. The input is borderless and transparent over a tertiary fill. Use it to filter or query a list.

Import ​

kotlin
import io.github.heartcoolman.prism.ui.PrismSearchField

Basic usage ​

kotlin
var query by remember { mutableStateOf("") }
PrismSearchField(
    value = query,
    onValueChange = { query = it },
    onClear = { query = "" },
)

Placeholder and full width ​

The placeholder defaults to "搜索". The clear button is shown automatically whenever value is non-empty and invokes onClear when pressed.

kotlin
PrismSearchField(
    value = query,
    onValueChange = { query = it },
    placeholder = "Search library",
    onClear = { query = "" },
    fullWidth = true,
)

API ​

ParameterTypeDefaultDescription
valueString—Current query text.
onValueChange(String) -> Unit—Called with the new value on each edit.
modifierModifierModifierLayout modifier applied to the field row.
placeholderString"搜索"Placeholder shown when the value is empty.
onClear(() -> Unit)?nullInvoked when the trailing clear button is pressed.
enabledBooleantrueWhether the field accepts input and the clear button is active.
fullWidthBooleanfalseStretch the field to fill the container width.

Released under the MIT License.