Compose Searchable Dropdown is a Jetpack Compose library for Android that provides a dropdown with a search bar.
Compose Searchable Dropdown is available on mavenCentral()
.
implementation("io.github.the-best-is-best:ComposeSearchableDropdown:2.1.1")
- fix jvm not implementation and need change gradle.properties check if add this
kotlin.native.cacheKind = none
compose.kotlin.native.manageCacheKind = false
- support compose and kotlin multiplatform
- The
searchIn
parameter can now be null (if null the search bar will be hidden)
data class ExampleData(
val id: Int,
val name: String
)
private val data = listOf(
ExampleData(1, "First"),
ExampleData(2, "Second"),
ExampleData(3, "Third"),
ExampleData(4, "Fourth"),
ExampleData(5, "Fifth"),
)
val selectedItemsState = rememberDropdownStates<ExampleData>(value = data[2])
Column{
SearchableDropDown(
listOfItems = data,
state = selectedItemsState,
placeholder = {
Text(text = "اختار")
},
searchPlaceHolder = {
Text(text = "بحث")
},
onDropDownItemSelected = {
Log.d("get v", it.name)
},
dropdownItem = {
Text("${it.id} - ${it.name}", fontSize = 20.sp)
},
selectedOptionTextDisplay = {it.name},
searchIn = {
it.name
}
)
}
- Can clear state
selectedItemsState.clear()
data class ExampleData(
val id: Int,
val name: String
)
private val data = listOf(
ExampleData(1, "First"),
ExampleData(2, "Second"),
ExampleData(3, "Third"),
ExampleData(4, "Fourth"),
ExampleData(5, "Fifth"),
)
SearchableDropDown(
listOfItems = data,
placeholder = {
Text(text = "Select an item")
},
searchPlaceHolder = {
Text(text = "Search an item")
},
defaultItem = data[2],
onDropDownItemSelected = {
Log.d("get v", it.name)
},
dropdownItem = {
Text("${it.id} - ${it.name}")
},
selectedOptionTextDisplay = {it.name},
searchIn = {it.name} // or it.id
)