Skip to content

Commit

Permalink
Add a placeholder on the search bar
Browse files Browse the repository at this point in the history
  • Loading branch information
dellisd committed Mar 15, 2024
1 parent 77c4b6b commit 49330fb
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import ca.derekellis.reroute.search.ui.SearchResult
import ca.derekellis.reroute.ui.AppStylesheet.SmallMediaQuery
import ca.derekellis.reroute.ui.View
import org.jetbrains.compose.web.attributes.InputType
import org.jetbrains.compose.web.attributes.placeholder
import org.jetbrains.compose.web.css.Color
import org.jetbrains.compose.web.css.DisplayStyle
import org.jetbrains.compose.web.css.FlexDirection
Expand Down Expand Up @@ -48,6 +49,7 @@ class SearchView : View<SearchViewModel, SearchViewEvent> {
classes(SearchStyleSheet.searchContainer)
}) {
SearchBar(
placeholder = "Search for stops",
onQueryUpdate = { q -> emit(SearchViewEvent.UpdateQuery(q)) },
onFocused = { isFocused = it },
)
Expand Down Expand Up @@ -119,13 +121,14 @@ object SearchStyleSheet : StyleSheet() {
* TODO: Think about how to best expose input events to parent composable. A flow?
*/
@Composable
fun SearchBar(onQueryUpdate: (String) -> Unit, onFocused: (focused: Boolean) -> Unit = {}) {
fun SearchBar(placeholder: String? = null, onQueryUpdate: (String) -> Unit, onFocused: (focused: Boolean) -> Unit = {}) {
Input(type = InputType.Search, attrs = {
classes(SearchStyleSheet.searchInput)
onInput {
onQueryUpdate(it.value)
}
onFocusIn { onFocused(true) }
onFocusOut { onFocused(false) }
placeholder?.let { placeholder(it) }
})
}

0 comments on commit 49330fb

Please sign in to comment.