Skip to content

Commit

Permalink
Trigger Search on Enter Key Press in Search Window
Browse files Browse the repository at this point in the history
  • Loading branch information
mehmedalijaK committed Feb 25, 2025
1 parent 5c3889d commit e7cb5af
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.imePadding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.HorizontalDivider
Expand Down Expand Up @@ -104,6 +105,12 @@ fun SearchScreen(
onQueryChange = {
eventPublisher(SearchContract.UiEvent.SearchQueryUpdated(query = it))
},
onSearch = {
keyboardController?.hide()
scope.launch {
onSearchContent(searchScope, state.searchQuery)
}
},
)
},
actions = {
Expand Down Expand Up @@ -178,6 +185,7 @@ fun SearchTextField(
query: String,
onQueryChange: (String) -> Unit,
focusRequester: FocusRequester = remember { FocusRequester() },
onSearch: () -> Unit,
) {
var focusRequested by rememberSaveable { mutableStateOf(false) }
LaunchedEffect(focusRequester) {
Expand All @@ -198,6 +206,11 @@ fun SearchTextField(
keyboardOptions = KeyboardOptions(
imeAction = ImeAction.Done,
),
keyboardActions = KeyboardActions(
onDone = {
onSearch()
},
),
singleLine = true,
)
}
Expand Down

0 comments on commit e7cb5af

Please sign in to comment.