From 950f761ba12cbcb1c3cbb6a696188e68cccea5f4 Mon Sep 17 00:00:00 2001 From: Ivan Matkov Date: Mon, 9 Dec 2024 18:07:12 +0100 Subject: [PATCH] Restore focusRequester in Slider --- .../commonMain/kotlin/androidx/compose/material/Slider.kt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Slider.kt b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Slider.kt index aa589909f7b3b..7f35d4cb65efb 100644 --- a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Slider.kt +++ b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Slider.kt @@ -70,6 +70,8 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.composed import androidx.compose.ui.draw.shadow +import androidx.compose.ui.focus.FocusRequester +import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.geometry.Offset import androidx.compose.ui.geometry.lerp import androidx.compose.ui.graphics.Color @@ -170,6 +172,7 @@ fun Slider( val onValueChangeFinishedState = rememberUpdatedState(onValueChangeFinished) val tickFractions = remember(steps) { stepsToTickFractions(steps) } + val focusRequester = remember { FocusRequester() } BoxWithConstraints( modifier .minimumInteractiveComponentSize() @@ -182,6 +185,7 @@ fun Slider( valueRange, steps ) + .focusRequester(focusRequester) .focusable(enabled, interactionSource) .slideOnKeyEvents( enabled, @@ -229,6 +233,7 @@ fun Slider( rememberUpdatedState<(Float) -> Unit> { velocity: Float -> val current = rawOffset.floatValue val target = snapValueToTick(current, tickFractions, minPx, maxPx) + focusRequester.requestFocus() if (current != target) { scope.launch { animateToTarget(draggableState, current, target, velocity)