Skip to content
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

Slider can be moved using keyboard, but cannot be submitted #2798

Closed
sebkur opened this issue Feb 25, 2023 · 2 comments · Fixed by JetBrains/compose-multiplatform-core#538
Closed
Assignees
Labels
bug Something isn't working focus management input Touch, mouse, keyboard input related reproduced

Comments

@sebkur
Copy link
Contributor

sebkur commented Feb 25, 2023

Describe the bug
I can navigate to a Slider using Tab navigation and once the thumb has keyboard focus, I can move it using arrow keys, home, end, page up, page down etc, however I cannot submit the new value using the "Enter" key in order to cause a value change finished event. I think it is a bug that this event does not get fired in any way when using the keyboard to change the slider value. Like this it is relatively useless to use the onValueChangeFinished event as we cannot rely on it being called when using the keyboard. It makes sense to use it for mouse-based changing of the value as the onValueChange callback gets called very often (with non-step values, also) and it can make sense to react to the onValueChangeFinished event to do something once the user is done setting a new value. I think a solution would be to either fire that event after every change of the slider using the keyboard as updates cannot happen as frequently as with the mouse where also lots of values in between the actual steps get reported as events. Another solution would be to fire the event when the user confirms the new value using "Enter".

Affected platforms
Select one of the platforms below:

  • Desktop

Versions

  • Kotlin version*: 1.7.20
  • Compose Multiplatform version*: 1.3.0
  • OS version(s)* (required for Desktop and iOS issues): Linux
  • OS architecture (x86 or arm64): x86
  • JDK (for desktop issues): 17

To Reproduce
Steps and/or the code snippet to reproduce the behavior:

Run this snippet

import androidx.compose.material.Slider
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.window.singleWindowApplication

fun main() {
    singleWindowApplication {
        val float = remember { mutableStateOf(5f) }
        Slider(
            float.value,
            onValueChange = { float.value = it; println("changed: $it") },
            onValueChangeFinished = { println("finished: ${float.value}") },
            valueRange = 0f..10f,
            steps = 9
        )
    }
  • drag the slider with the mouse and observe both "changed: ..." and "finished: ..." output on stdout
  • move the slider with the arrows key and observer "changed: ..." output on stdout, but no "finished: ..." output, even when pressing "Enter" key

Expected behavior
It should be possible to trigger an onValueChangeFinished somehow using the keyboard. Either on "Enter" or just after every change of the value.

@sebkur sebkur added bug Something isn't working submitted labels Feb 25, 2023
@igordmn
Copy link
Collaborator

igordmn commented Feb 28, 2023

Thanks!

Reproduced.

We should call onValueChangeFinished?.invoke() here

@okushnikov
Copy link
Collaborator

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working focus management input Touch, mouse, keyboard input related reproduced
Projects
None yet
4 participants