External Keyboard Causes Line Break Instead of Search on Android - Kotlin

Viewed 112

Pressing Enter/Submit when the user focus is in the search creates a new line break rather than submitting the search.

This appears to only happen in an emulated environment with a physical keyboard.

The text input is androidx Jetpack Compose. I added the lines:

singleLine = true,

maxLines = 1,

to the OutlinedTextField, but all that did was prevent the textbox from expanding to the next line.

You can see in the screenshot below that the cursor moves to the next line. The cursor is there and is barely visible, but the only change was that the text field no longer expands to a second row:

Search works just fine with the on-screen keyboard, so that's not the issue. The issue only seems to be with external, physical keyboards.

1 Answers

Use an onQueryTextChanged on the searchView, and if you see a \n inserted delete it and trigger a search

Related