Skip to content

Commit

Permalink
Fix SearchBar key event condition (#811)
Browse files Browse the repository at this point in the history
## Proposed Changes

Addition to #801

## Testing

Test: Don't change the state in `onActiveChange`, press `Esc` - it was
called twice
  • Loading branch information
MatkovIvan authored and igordmn committed Jan 30, 2024
1 parent 9294cce commit aa8667e
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.graphics.takeOrElse
import androidx.compose.ui.input.key.Key
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.layout.layout
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalFocusManager
Expand Down Expand Up @@ -457,7 +459,7 @@ private fun SearchBarInputField(
.focusRequester(focusRequester)
.onFocusChanged { if (it.isFocused) onActiveChange(true) }
.onKeyEvent {
if (it.key == Key.Escape) {
if (it.key == Key.Escape && it.type == KeyEventType.KeyDown) {
onActiveChange(false)
true
} else {
Expand Down

0 comments on commit aa8667e

Please sign in to comment.