-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not possible to tab to next text field (or previous) #109
Comments
We definitely need to have better support for controlling focus by a keyboard. Meantime you can intercept keyboard events like described here https://github.com/JetBrains/compose-jb/tree/master/tutorials/Keyboard |
Great thanks I tried this but ran into a few problems. Key.Tab still doesn't fire the |
Could you please provide a code example where you see such problems? |
Hi please replace this file in the codeviewer example https://github.com/JetBrains/compose-jb/blob/master/examples/codeviewer/common/src/desktopMain/kotlin/org/jetbrains/codeviewer/platform/Theme.kt
|
Seeing the same issue. |
There's currently no access to the |
i have something that kind of works for this val content0 = remember { mutableStateOf("") }
val content1 = remember { mutableStateOf("") }
val focusFirst = FocusRequester.Default
val focusSecond = FocusRequester.Default
Column {
TextField(
content0.value, onValueChange = { content0.value = it },
modifier = Modifier.focusRequester(focusFirst)
.onKeyEvent {
when (it.key) {
Key.Tab -> {
focusSecond.requestFocus()
true
}
else -> false
}
}
)
TextField(
value = content1.value, onValueChange = { content1.value = it },
modifier = Modifier.focusRequester(focusSecond).shortcuts {
on(Key.ShiftLeft + Key.Tab) {
focusFirst.requestFocus()
}
}
)
}
but now i'm running into a seperate issue where |
@Rsedaikin does your tab-navigation implementation cover this? |
Any fix soon ? |
@Ayfri tab-navigation is available in build 0.5.0-build262. Try to see if it fits you needs. |
This is still an issue with version 1.1.1 for multiline text fields (not for single line ones). As a reference, we are using the following workaround: @OptIn(ExperimentalComposeUiApi::class)
@Composable
fun Modifier.moveFocusOnTab(
focusManager: FocusManager = LocalFocusManager.current
) = onPreviewKeyEvent {
if (it.type == KeyEventType.KeyDown && it.key == Key.Tab) {
focusManager.moveFocus(
if (it.isShiftPressed) FocusDirection.Previous
else FocusDirection.Next
)
return@onPreviewKeyEvent true
}
false
} |
The bug with multiline textfields should be mentioned in the tab tutorial https://github.com/JetBrains/compose-jb/tree/master/tutorials/Tab_Navigation |
Made PR with this workaround code snippet: |
I am making a login form. I have 2
OutlinedTextFields
. I can addImeAction
s for the Enter key, but there seems to be no option for the tab key. Furthermore,onValueChange
is not called when I press the tab key by default, so there is no way to detect pressing tab, and shift focus to the next text field.This is running on MacOs 11.0.1
The text was updated successfully, but these errors were encountered: