Skip to content

Commit

Permalink
Hide keyboard when search clear button is clicked
Browse files Browse the repository at this point in the history
  • Loading branch information
Siddharth Agarwal committed Aug 14, 2024
1 parent 55402cf commit 4397537
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import androidx.compose.ui.input.key.KeyEventType
import androidx.compose.ui.input.key.key
import androidx.compose.ui.input.key.onKeyEvent
import androidx.compose.ui.input.key.type
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.semantics.contentDescription
Expand Down Expand Up @@ -71,6 +72,8 @@ fun SearchBar(
val interactionSource = remember { MutableInteractionSource() }
val isPressed by interactionSource.collectIsPressedAsState()
val focusRequester = remember { FocusRequester() }
val keyboardController = LocalSoftwareKeyboardController.current

val containerColor = if (!isPressed) {
SurfaceColor.ContainerLow
} else {
Expand Down Expand Up @@ -148,6 +151,7 @@ fun SearchBar(
},
onClick = {
onQueryChange.invoke("")
keyboardController?.hide()
},
)
} else {
Expand Down

0 comments on commit 4397537

Please sign in to comment.