JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
14.85k stars 1.08k forks source link

Make Tab + Shift Tab move focus on Web #4714

Open iruizmar opened 3 weeks ago

iruizmar commented 3 weeks ago

I found this document stating that Tab and Shift+Tab are supposed to automatically move the focus to the next/previous focusable element but I supposed this is only for Compose Desktop because it's not working on a JS app.

It's easy to add by re-adding manually the moveFocusOnTab modifier that used to be on that document:

fun Modifier.moveFocusOnTab() = composed {
    val focusManager = LocalFocusManager.current
    onPreviewKeyEvent {
        if (it.type == KeyEventType.KeyDown && it.key == Key.Tab) {
            focusManager.moveFocus(
                if (it.isShiftPressed) FocusDirection.Previous else FocusDirection.Next
            )
            true
        } else {
            false
        }
    }
}

But it'd be cool if this was happening automatically.

Thanks!