From fcf135df5d7bdb00b112aaab87c7784c3ebaf9fa Mon Sep 17 00:00:00 2001 From: Illia Achour Date: Sat, 26 Sep 2026 20:46:59 -0400 Subject: [PATCH 1/4] Keep the restore a button while there is nothing to restore The dialog's header made the original half a button only once the color was edited, so a screen reader met a plain swatch first and a button after an edit, with nothing saying why it appeared. BasicColorComparison and ColorComparison take enabled, and the header keeps the half a button that is disabled until the color is modified. A disabled comparison draws its colors unchanged: dimmed, the swatch would show colors other than the ones compared. The header also converts the original color once rather than on every frame of a drag. --- .../api/colorpicker-foundation.klib.api | 2 +- .../api/jvm/colorpicker-foundation.api | 2 +- .../foundation/BasicColorComparison.kt | 5 +++- .../foundation/BasicColorComparisonTest.kt | 15 +++++++++++ .../api/colorpicker-material3.klib.api | 2 +- .../api/jvm/colorpicker-material3.api | 2 +- .../colorpicker/material3/ColorComparison.kt | 4 +++ .../material3/ColorPickerDialogDefaults.kt | 12 +++++---- .../material3/ColorPickerDialogTest.kt | 25 ++++++++++++++++--- 9 files changed, 56 insertions(+), 13 deletions(-) diff --git a/colorpicker-foundation/api/colorpicker-foundation.klib.api b/colorpicker-foundation/api/colorpicker-foundation.klib.api index b6fc30fe..2b1d6edc 100644 --- a/colorpicker-foundation/api/colorpicker-foundation.klib.api +++ b/colorpicker-foundation/api/colorpicker-foundation.klib.api @@ -212,7 +212,7 @@ final fun (codes.side.colorpicker.state/ColorPickerState).codes.side.colorpicker final fun codes.side.colorpicker.foundation/BasicAlphaSlider(codes.side.colorpicker.state/ColorPickerState, androidx.compose.ui/Modifier?, kotlin/Boolean, kotlin/Function0?, kotlin/String?, kotlin/String?, androidx.compose.foundation.interaction/MutableInteractionSource?, kotlin/Function3, kotlin/Function3, androidx.compose.runtime/Composer?, kotlin/Int, kotlin/Int) // codes.side.colorpicker.foundation/BasicAlphaSlider|BasicAlphaSlider(codes.side.colorpicker.state.ColorPickerState;androidx.compose.ui.Modifier?;kotlin.Boolean;kotlin.Function0?;kotlin.String?;kotlin.String?;androidx.compose.foundation.interaction.MutableInteractionSource?;kotlin.Function3;kotlin.Function3;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int){}[0] final fun codes.side.colorpicker.foundation/BasicChannelPlane(codes.side.colorpicker.state/ColorPickerState, codes.side.color/ColorChannel, codes.side.color/ColorChannel, androidx.compose.ui/Modifier?, kotlin/Boolean, kotlin/Function0?, androidx.compose.ui.graphics/Shape?, kotlin/String?, kotlin/String?, codes.side.colorpicker.foundation/PlaneActionLabels?, androidx.compose.foundation.interaction/MutableInteractionSource?, kotlin/Function3, androidx.compose.runtime/Composer?, kotlin/Int, kotlin/Int, kotlin/Int) // codes.side.colorpicker.foundation/BasicChannelPlane|BasicChannelPlane(codes.side.colorpicker.state.ColorPickerState;codes.side.color.ColorChannel;codes.side.color.ColorChannel;androidx.compose.ui.Modifier?;kotlin.Boolean;kotlin.Function0?;androidx.compose.ui.graphics.Shape?;kotlin.String?;kotlin.String?;codes.side.colorpicker.foundation.PlaneActionLabels?;androidx.compose.foundation.interaction.MutableInteractionSource?;kotlin.Function3;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int;kotlin.Int){}[0] final fun codes.side.colorpicker.foundation/BasicChannelSlider(codes.side.colorpicker.state/ColorPickerState, codes.side.color/ColorChannel, androidx.compose.ui/Modifier?, kotlin/Boolean, kotlin.ranges/ClosedFloatingPointRange?, codes.side.colorpicker.state/ColoringMode?, kotlin/Function0?, kotlin/String?, kotlin/String?, androidx.compose.foundation.interaction/MutableInteractionSource?, kotlin/Function3, kotlin/Function3, androidx.compose.runtime/Composer?, kotlin/Int, kotlin/Int, kotlin/Int) // codes.side.colorpicker.foundation/BasicChannelSlider|BasicChannelSlider(codes.side.colorpicker.state.ColorPickerState;codes.side.color.ColorChannel;androidx.compose.ui.Modifier?;kotlin.Boolean;kotlin.ranges.ClosedFloatingPointRange?;codes.side.colorpicker.state.ColoringMode?;kotlin.Function0?;kotlin.String?;kotlin.String?;androidx.compose.foundation.interaction.MutableInteractionSource?;kotlin.Function3;kotlin.Function3;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int;kotlin.Int){}[0] -final fun codes.side.colorpicker.foundation/BasicColorComparison(androidx.compose.ui.graphics/Color, androidx.compose.ui.graphics/Color, kotlin/Function0?, androidx.compose.ui/Modifier?, androidx.compose.ui.graphics/Color, androidx.compose.ui.graphics/Color, kotlin/String?, kotlin/String?, kotlin/String?, androidx.compose.runtime/Composer?, kotlin/Int, kotlin/Int) // codes.side.colorpicker.foundation/BasicColorComparison|BasicColorComparison(androidx.compose.ui.graphics.Color;androidx.compose.ui.graphics.Color;kotlin.Function0?;androidx.compose.ui.Modifier?;androidx.compose.ui.graphics.Color;androidx.compose.ui.graphics.Color;kotlin.String?;kotlin.String?;kotlin.String?;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int){}[0] +final fun codes.side.colorpicker.foundation/BasicColorComparison(androidx.compose.ui.graphics/Color, androidx.compose.ui.graphics/Color, kotlin/Function0?, androidx.compose.ui/Modifier?, kotlin/Boolean, androidx.compose.ui.graphics/Color, androidx.compose.ui.graphics/Color, kotlin/String?, kotlin/String?, kotlin/String?, androidx.compose.runtime/Composer?, kotlin/Int, kotlin/Int) // codes.side.colorpicker.foundation/BasicColorComparison|BasicColorComparison(androidx.compose.ui.graphics.Color;androidx.compose.ui.graphics.Color;kotlin.Function0?;androidx.compose.ui.Modifier?;kotlin.Boolean;androidx.compose.ui.graphics.Color;androidx.compose.ui.graphics.Color;kotlin.String?;kotlin.String?;kotlin.String?;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int){}[0] final fun codes.side.colorpicker.foundation/BasicColorPicker(androidx.compose.ui.graphics/Color, kotlin/Function1, codes.side.color/ColorSpace, kotlin/Function5?, kotlin/Function4, kotlin/Function3?, androidx.compose.ui/Modifier?, kotlin/Boolean, androidx.compose.foundation.gestures/Orientation?, androidx.compose.ui.unit/Dp, androidx.compose.runtime/Composer?, kotlin/Int, kotlin/Int) // codes.side.colorpicker.foundation/BasicColorPicker|BasicColorPicker(androidx.compose.ui.graphics.Color;kotlin.Function1;codes.side.color.ColorSpace;kotlin.Function5?;kotlin.Function4;kotlin.Function3?;androidx.compose.ui.Modifier?;kotlin.Boolean;androidx.compose.foundation.gestures.Orientation?;androidx.compose.ui.unit.Dp;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int){}[0] final fun codes.side.colorpicker.foundation/BasicColorPicker(codes.side.color/ColorValue, kotlin/Function1, codes.side.color/ColorSpace, kotlin/Function5?, kotlin/Function4, kotlin/Function3?, androidx.compose.ui/Modifier?, kotlin/Boolean, androidx.compose.foundation.gestures/Orientation?, androidx.compose.ui.unit/Dp, androidx.compose.runtime/Composer?, kotlin/Int, kotlin/Int) // codes.side.colorpicker.foundation/BasicColorPicker|BasicColorPicker(codes.side.color.ColorValue;kotlin.Function1;codes.side.color.ColorSpace;kotlin.Function5?;kotlin.Function4;kotlin.Function3?;androidx.compose.ui.Modifier?;kotlin.Boolean;androidx.compose.foundation.gestures.Orientation?;androidx.compose.ui.unit.Dp;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int){}[0] final fun codes.side.colorpicker.foundation/BasicColorPicker(codes.side.colorpicker.state/ColorPickerState, codes.side.color/ColorSpace, kotlin/Function5?, kotlin/Function4, kotlin/Function3?, androidx.compose.ui/Modifier?, kotlin/Boolean, androidx.compose.foundation.gestures/Orientation?, androidx.compose.ui.unit/Dp, androidx.compose.runtime/Composer?, kotlin/Int, kotlin/Int) // codes.side.colorpicker.foundation/BasicColorPicker|BasicColorPicker(codes.side.colorpicker.state.ColorPickerState;codes.side.color.ColorSpace;kotlin.Function5?;kotlin.Function4;kotlin.Function3?;androidx.compose.ui.Modifier?;kotlin.Boolean;androidx.compose.foundation.gestures.Orientation?;androidx.compose.ui.unit.Dp;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int){}[0] diff --git a/colorpicker-foundation/api/jvm/colorpicker-foundation.api b/colorpicker-foundation/api/jvm/colorpicker-foundation.api index 7b1ca0be..f75fbd51 100644 --- a/colorpicker-foundation/api/jvm/colorpicker-foundation.api +++ b/colorpicker-foundation/api/jvm/colorpicker-foundation.api @@ -16,7 +16,7 @@ public final class codes/side/colorpicker/foundation/BasicChannelSliderKt { } public final class codes/side/colorpicker/foundation/BasicColorComparisonKt { - public static final fun BasicColorComparison-ep2nmRk (JJLkotlin/jvm/functions/Function0;Landroidx/compose/ui/Modifier;JJLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Landroidx/compose/runtime/Composer;II)V + public static final fun BasicColorComparison-VALQH9M (JJLkotlin/jvm/functions/Function0;Landroidx/compose/ui/Modifier;ZJJLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Landroidx/compose/runtime/Composer;II)V } public final class codes/side/colorpicker/foundation/BasicColorPickerDialogContentKt { diff --git a/colorpicker-foundation/src/commonMain/kotlin/codes/side/colorpicker/foundation/BasicColorComparison.kt b/colorpicker-foundation/src/commonMain/kotlin/codes/side/colorpicker/foundation/BasicColorComparison.kt index 4e55eca5..518fe64e 100644 --- a/colorpicker-foundation/src/commonMain/kotlin/codes/side/colorpicker/foundation/BasicColorComparison.kt +++ b/colorpicker-foundation/src/commonMain/kotlin/codes/side/colorpicker/foundation/BasicColorComparison.kt @@ -18,6 +18,8 @@ import androidx.compose.ui.semantics.semantics * * @param onRestoreOriginal called when the original half is pressed, which makes that half a button that puts * the original back; `null` leaves it a swatch. + * @param enabled when false the original half, when it is a button, is a disabled one: pressing it restores + * nothing, it takes no focus, and a screen reader hears that it is disabled. * @param originalLabel what a screen reader calls the original half, "Original color" by default; `null` says * nothing. * @param currentLabel what a screen reader calls the current half, "New color" by default; `null` says @@ -31,6 +33,7 @@ public fun BasicColorComparison( current: Color, onRestoreOriginal: (() -> Unit)?, modifier: Modifier = Modifier, + enabled: Boolean = true, checkerboardLight: Color = Color.White, checkerboardDark: Color = Color.LightGray, originalLabel: String? = ColorPickerStrings.current.originalColor(), @@ -42,7 +45,7 @@ public fun BasicColorComparison( // as in a scrolling column, is one fillMaxHeight cannot fill. Row(Modifier.matchParentSize()) { val restore = if (onRestoreOriginal != null) { - Modifier.clickable(onClickLabel = restoreLabel, role = Role.Button, onClick = onRestoreOriginal) + Modifier.clickable(enabled = enabled, onClickLabel = restoreLabel, role = Role.Button, onClick = onRestoreOriginal) } else { Modifier } diff --git a/colorpicker-foundation/src/jvmTest/kotlin/codes/side/colorpicker/foundation/BasicColorComparisonTest.kt b/colorpicker-foundation/src/jvmTest/kotlin/codes/side/colorpicker/foundation/BasicColorComparisonTest.kt index 620c2b17..de5a3998 100644 --- a/colorpicker-foundation/src/jvmTest/kotlin/codes/side/colorpicker/foundation/BasicColorComparisonTest.kt +++ b/colorpicker-foundation/src/jvmTest/kotlin/codes/side/colorpicker/foundation/BasicColorComparisonTest.kt @@ -22,6 +22,7 @@ import androidx.compose.ui.test.ExperimentalTestApi import androidx.compose.ui.test.SemanticsMatcher import androidx.compose.ui.test.assert import androidx.compose.ui.test.assertHeightIsEqualTo +import androidx.compose.ui.test.assertIsNotEnabled import androidx.compose.ui.test.captureToImage import androidx.compose.ui.test.onNodeWithContentDescription import androidx.compose.ui.test.onNodeWithTag @@ -54,6 +55,20 @@ class BasicColorComparisonTest { assertEquals(1, restored) } + @Test + fun aDisabledRestoreIsAButtonThatRestoresNothing() = runComposeUiTest { + var restored = 0 + setContent { + BasicColorComparison(Color.Red, Color.Blue, onRestoreOriginal = { restored++ }, Modifier.size(96.dp, 48.dp), enabled = false) + } + onNodeWithContentDescription("Original color") + .assert(SemanticsMatcher.expectValue(SemanticsProperties.Role, Role.Button)) + .assertIsNotEnabled() + .assert(SemanticsMatcher.keyNotDefined(SemanticsActions.RequestFocus)) + .performClick() + assertEquals(0, restored) + } + @Test fun withNothingToRestoreTheOriginalHalfIsNoButton() = runComposeUiTest { setContent { BasicColorComparison(Color.Red, Color.Blue, onRestoreOriginal = null, Modifier.size(96.dp, 48.dp)) } diff --git a/colorpicker-material3/api/colorpicker-material3.klib.api b/colorpicker-material3/api/colorpicker-material3.klib.api index 0c316bea..64c29505 100644 --- a/colorpicker-material3/api/colorpicker-material3.klib.api +++ b/colorpicker-material3/api/colorpicker-material3.klib.api @@ -124,7 +124,7 @@ final fun codes.side.colorpicker.material3/ChannelSlider(codes.side.colorpicker. final fun codes.side.colorpicker.material3/CmykColorPicker(androidx.compose.ui.graphics/Color, kotlin/Function1, androidx.compose.ui/Modifier?, kotlin/Boolean, androidx.compose.foundation.gestures/Orientation?, codes.side.colorpicker.state/ColoringMode?, kotlin/Function0?, codes.side.colorpicker.material3/ColorPickerColors?, codes.side.colorpicker.material3/ColorPickerShapes?, codes.side.colorpicker.material3/ColorPickerDimensions?, kotlin/Function3?, kotlin/Function5?, kotlin/Function4?, kotlin/Function3?, androidx.compose.runtime/Composer?, kotlin/Int, kotlin/Int, kotlin/Int) // codes.side.colorpicker.material3/CmykColorPicker|CmykColorPicker(androidx.compose.ui.graphics.Color;kotlin.Function1;androidx.compose.ui.Modifier?;kotlin.Boolean;androidx.compose.foundation.gestures.Orientation?;codes.side.colorpicker.state.ColoringMode?;kotlin.Function0?;codes.side.colorpicker.material3.ColorPickerColors?;codes.side.colorpicker.material3.ColorPickerShapes?;codes.side.colorpicker.material3.ColorPickerDimensions?;kotlin.Function3?;kotlin.Function5?;kotlin.Function4?;kotlin.Function3?;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int;kotlin.Int){}[0] final fun codes.side.colorpicker.material3/CmykColorPicker(codes.side.color/ColorValue, kotlin/Function1, androidx.compose.ui/Modifier?, kotlin/Boolean, androidx.compose.foundation.gestures/Orientation?, codes.side.colorpicker.state/ColoringMode?, kotlin/Function0?, codes.side.colorpicker.material3/ColorPickerColors?, codes.side.colorpicker.material3/ColorPickerShapes?, codes.side.colorpicker.material3/ColorPickerDimensions?, kotlin/Function3?, kotlin/Function5?, kotlin/Function4?, kotlin/Function3?, androidx.compose.runtime/Composer?, kotlin/Int, kotlin/Int, kotlin/Int) // codes.side.colorpicker.material3/CmykColorPicker|CmykColorPicker(codes.side.color.ColorValue;kotlin.Function1;androidx.compose.ui.Modifier?;kotlin.Boolean;androidx.compose.foundation.gestures.Orientation?;codes.side.colorpicker.state.ColoringMode?;kotlin.Function0?;codes.side.colorpicker.material3.ColorPickerColors?;codes.side.colorpicker.material3.ColorPickerShapes?;codes.side.colorpicker.material3.ColorPickerDimensions?;kotlin.Function3?;kotlin.Function5?;kotlin.Function4?;kotlin.Function3?;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int;kotlin.Int){}[0] final fun codes.side.colorpicker.material3/CmykColorPicker(codes.side.colorpicker.state/ColorPickerState, androidx.compose.ui/Modifier?, kotlin/Boolean, androidx.compose.foundation.gestures/Orientation?, codes.side.colorpicker.state/ColoringMode?, kotlin/Function0?, codes.side.colorpicker.material3/ColorPickerColors?, codes.side.colorpicker.material3/ColorPickerShapes?, codes.side.colorpicker.material3/ColorPickerDimensions?, kotlin/Function3?, kotlin/Function5?, kotlin/Function4?, kotlin/Function3?, androidx.compose.runtime/Composer?, kotlin/Int, kotlin/Int, kotlin/Int) // codes.side.colorpicker.material3/CmykColorPicker|CmykColorPicker(codes.side.colorpicker.state.ColorPickerState;androidx.compose.ui.Modifier?;kotlin.Boolean;androidx.compose.foundation.gestures.Orientation?;codes.side.colorpicker.state.ColoringMode?;kotlin.Function0?;codes.side.colorpicker.material3.ColorPickerColors?;codes.side.colorpicker.material3.ColorPickerShapes?;codes.side.colorpicker.material3.ColorPickerDimensions?;kotlin.Function3?;kotlin.Function5?;kotlin.Function4?;kotlin.Function3?;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int;kotlin.Int){}[0] -final fun codes.side.colorpicker.material3/ColorComparison(androidx.compose.ui.graphics/Color, androidx.compose.ui.graphics/Color, kotlin/Function0?, androidx.compose.ui/Modifier?, androidx.compose.ui.graphics/Shape?, codes.side.colorpicker.material3/ColorPickerColors?, kotlin/String?, kotlin/String?, kotlin/String?, androidx.compose.runtime/Composer?, kotlin/Int, kotlin/Int) // codes.side.colorpicker.material3/ColorComparison|ColorComparison(androidx.compose.ui.graphics.Color;androidx.compose.ui.graphics.Color;kotlin.Function0?;androidx.compose.ui.Modifier?;androidx.compose.ui.graphics.Shape?;codes.side.colorpicker.material3.ColorPickerColors?;kotlin.String?;kotlin.String?;kotlin.String?;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int){}[0] +final fun codes.side.colorpicker.material3/ColorComparison(androidx.compose.ui.graphics/Color, androidx.compose.ui.graphics/Color, kotlin/Function0?, androidx.compose.ui/Modifier?, kotlin/Boolean, androidx.compose.ui.graphics/Shape?, codes.side.colorpicker.material3/ColorPickerColors?, kotlin/String?, kotlin/String?, kotlin/String?, androidx.compose.runtime/Composer?, kotlin/Int, kotlin/Int) // codes.side.colorpicker.material3/ColorComparison|ColorComparison(androidx.compose.ui.graphics.Color;androidx.compose.ui.graphics.Color;kotlin.Function0?;androidx.compose.ui.Modifier?;kotlin.Boolean;androidx.compose.ui.graphics.Shape?;codes.side.colorpicker.material3.ColorPickerColors?;kotlin.String?;kotlin.String?;kotlin.String?;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int){}[0] final fun codes.side.colorpicker.material3/ColorPicker(androidx.compose.ui.graphics/Color, kotlin/Function1, androidx.compose.ui/Modifier?, codes.side.color/ColorSpace?, kotlin/Boolean, androidx.compose.foundation.gestures/Orientation?, codes.side.colorpicker.state/ColoringMode?, kotlin/Function0?, codes.side.colorpicker.material3/ColorPickerColors?, codes.side.colorpicker.material3/ColorPickerShapes?, codes.side.colorpicker.material3/ColorPickerDimensions?, kotlin/Function3?, kotlin/Function5?, kotlin/Function4?, kotlin/Function3?, androidx.compose.runtime/Composer?, kotlin/Int, kotlin/Int, kotlin/Int) // codes.side.colorpicker.material3/ColorPicker|ColorPicker(androidx.compose.ui.graphics.Color;kotlin.Function1;androidx.compose.ui.Modifier?;codes.side.color.ColorSpace?;kotlin.Boolean;androidx.compose.foundation.gestures.Orientation?;codes.side.colorpicker.state.ColoringMode?;kotlin.Function0?;codes.side.colorpicker.material3.ColorPickerColors?;codes.side.colorpicker.material3.ColorPickerShapes?;codes.side.colorpicker.material3.ColorPickerDimensions?;kotlin.Function3?;kotlin.Function5?;kotlin.Function4?;kotlin.Function3?;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int;kotlin.Int){}[0] final fun codes.side.colorpicker.material3/ColorPicker(codes.side.color/ColorValue, kotlin/Function1, androidx.compose.ui/Modifier?, codes.side.color/ColorSpace?, kotlin/Boolean, androidx.compose.foundation.gestures/Orientation?, codes.side.colorpicker.state/ColoringMode?, kotlin/Function0?, codes.side.colorpicker.material3/ColorPickerColors?, codes.side.colorpicker.material3/ColorPickerShapes?, codes.side.colorpicker.material3/ColorPickerDimensions?, kotlin/Function3?, kotlin/Function5?, kotlin/Function4?, kotlin/Function3?, androidx.compose.runtime/Composer?, kotlin/Int, kotlin/Int, kotlin/Int) // codes.side.colorpicker.material3/ColorPicker|ColorPicker(codes.side.color.ColorValue;kotlin.Function1;androidx.compose.ui.Modifier?;codes.side.color.ColorSpace?;kotlin.Boolean;androidx.compose.foundation.gestures.Orientation?;codes.side.colorpicker.state.ColoringMode?;kotlin.Function0?;codes.side.colorpicker.material3.ColorPickerColors?;codes.side.colorpicker.material3.ColorPickerShapes?;codes.side.colorpicker.material3.ColorPickerDimensions?;kotlin.Function3?;kotlin.Function5?;kotlin.Function4?;kotlin.Function3?;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int;kotlin.Int){}[0] final fun codes.side.colorpicker.material3/ColorPicker(codes.side.colorpicker.state/ColorPickerState, androidx.compose.ui/Modifier?, codes.side.color/ColorSpace?, kotlin/Boolean, androidx.compose.foundation.gestures/Orientation?, codes.side.colorpicker.state/ColoringMode?, kotlin/Function0?, codes.side.colorpicker.material3/ColorPickerColors?, codes.side.colorpicker.material3/ColorPickerShapes?, codes.side.colorpicker.material3/ColorPickerDimensions?, kotlin/Function3?, kotlin/Function5?, kotlin/Function4?, kotlin/Function3?, androidx.compose.runtime/Composer?, kotlin/Int, kotlin/Int, kotlin/Int) // codes.side.colorpicker.material3/ColorPicker|ColorPicker(codes.side.colorpicker.state.ColorPickerState;androidx.compose.ui.Modifier?;codes.side.color.ColorSpace?;kotlin.Boolean;androidx.compose.foundation.gestures.Orientation?;codes.side.colorpicker.state.ColoringMode?;kotlin.Function0?;codes.side.colorpicker.material3.ColorPickerColors?;codes.side.colorpicker.material3.ColorPickerShapes?;codes.side.colorpicker.material3.ColorPickerDimensions?;kotlin.Function3?;kotlin.Function5?;kotlin.Function4?;kotlin.Function3?;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int;kotlin.Int){}[0] diff --git a/colorpicker-material3/api/jvm/colorpicker-material3.api b/colorpicker-material3/api/jvm/colorpicker-material3.api index 81d2ebf4..1a082d9b 100644 --- a/colorpicker-material3/api/jvm/colorpicker-material3.api +++ b/colorpicker-material3/api/jvm/colorpicker-material3.api @@ -17,7 +17,7 @@ public final class codes/side/colorpicker/material3/CmykColorPickerKt { } public final class codes/side/colorpicker/material3/ColorComparisonKt { - public static final fun ColorComparison-9TxLVRM (JJLkotlin/jvm/functions/Function0;Landroidx/compose/ui/Modifier;Landroidx/compose/ui/graphics/Shape;Lcodes/side/colorpicker/material3/ColorPickerColors;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Landroidx/compose/runtime/Composer;II)V + public static final fun ColorComparison-7TXmnS8 (JJLkotlin/jvm/functions/Function0;Landroidx/compose/ui/Modifier;ZLandroidx/compose/ui/graphics/Shape;Lcodes/side/colorpicker/material3/ColorPickerColors;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Landroidx/compose/runtime/Composer;II)V } public final class codes/side/colorpicker/material3/ColorPickerColors { diff --git a/colorpicker-material3/src/commonMain/kotlin/codes/side/colorpicker/material3/ColorComparison.kt b/colorpicker-material3/src/commonMain/kotlin/codes/side/colorpicker/material3/ColorComparison.kt index 8b113cf1..86cc99f5 100644 --- a/colorpicker-material3/src/commonMain/kotlin/codes/side/colorpicker/material3/ColorComparison.kt +++ b/colorpicker-material3/src/commonMain/kotlin/codes/side/colorpicker/material3/ColorComparison.kt @@ -17,6 +17,8 @@ import codes.side.colorpicker.foundation.ColorPickerStrings * * @param onRestoreOriginal called when the original half is pressed, which makes that half a button that puts * the original back; `null` leaves it a swatch. + * @param enabled when false the original half, when it is a button, is a disabled one. The colors are drawn as + * they are either way, since a dimmed swatch would show colors other than the ones compared. * @param colors checkerboard colors; see [ColorPickerDefaults.colors]. * @param originalLabel what a screen reader calls the original half; `null` says nothing. * @param currentLabel what a screen reader calls the current half; `null` says nothing. @@ -28,6 +30,7 @@ public fun ColorComparison( current: Color, onRestoreOriginal: (() -> Unit)?, modifier: Modifier = Modifier, + enabled: Boolean = true, shape: Shape = ColorPickerDefaults.currentShapes().swatchShape, colors: ColorPickerColors = ColorPickerDefaults.currentColors(), originalLabel: String? = ColorPickerStrings.current.originalColor(), @@ -41,6 +44,7 @@ public fun ColorComparison( modifier = modifier .defaultMinSize(minWidth = ColorPickerDefaults.SwatchSize * 2, minHeight = ColorPickerDefaults.SwatchSize) .clip(shape), + enabled = enabled, checkerboardLight = colors.checkerboardLight, checkerboardDark = colors.checkerboardDark, originalLabel = originalLabel, diff --git a/colorpicker-material3/src/commonMain/kotlin/codes/side/colorpicker/material3/ColorPickerDialogDefaults.kt b/colorpicker-material3/src/commonMain/kotlin/codes/side/colorpicker/material3/ColorPickerDialogDefaults.kt index 1eb443c4..30fa062b 100644 --- a/colorpicker-material3/src/commonMain/kotlin/codes/side/colorpicker/material3/ColorPickerDialogDefaults.kt +++ b/colorpicker-material3/src/commonMain/kotlin/codes/side/colorpicker/material3/ColorPickerDialogDefaults.kt @@ -70,24 +70,26 @@ public object ColorPickerDialogDefaults { /** * The dialog's header: a [ColorComparison] of [state]'s original and edited colors, and the edited color in - * hex, `#RRGGBB`, with alpha's two digits after it when the color is not opaque. Pressing the original half - * puts the original back while the color is modified. + * hex, `#RRGGBB`, with alpha's two digits after it when the color is not opaque. The original half is a button + * that puts the original back, enabled while the color is modified. * - * @param enabled when false the original half does not restore. + * @param enabled when false the original half is a disabled button. */ @Composable public fun Header(state: ColorPickerDialogState, modifier: Modifier = Modifier, enabled: Boolean = true) { val value = state.pickerState.value + val original = remember(state.original) { state.original.toComposeColor() } Row( modifier = modifier, horizontalArrangement = Arrangement.spacedBy(HeaderSpacing), verticalAlignment = Alignment.CenterVertically, ) { ColorComparison( - original = state.original.toComposeColor(), + original = original, current = state.pickerState.color, - onRestoreOriginal = if (enabled && state.isModified) state::revert else null, + onRestoreOriginal = state::revert, modifier = Modifier.weight(1f), + enabled = enabled && state.isModified, ) // Monospaced, so the hex keeps its width while a slider moves. Text(value.toHexString(if (value.alpha == 1.0) HexAlpha.None else HexAlpha.Last), fontFamily = FontFamily.Monospace) diff --git a/colorpicker-material3/src/jvmTest/kotlin/codes/side/colorpicker/material3/ColorPickerDialogTest.kt b/colorpicker-material3/src/jvmTest/kotlin/codes/side/colorpicker/material3/ColorPickerDialogTest.kt index cb285063..7dfec1ef 100644 --- a/colorpicker-material3/src/jvmTest/kotlin/codes/side/colorpicker/material3/ColorPickerDialogTest.kt +++ b/colorpicker-material3/src/jvmTest/kotlin/codes/side/colorpicker/material3/ColorPickerDialogTest.kt @@ -279,11 +279,30 @@ class ColorPickerDialogTest { } @Test - fun theOriginalRestoresOnlyOnceTheColorIsEdited() = runComposeUiTest { + fun theRestoreIsEnabledOnlyOnceTheColorIsEdited() = runComposeUiTest { setContent { ColorPickerDialog(initialValue = teal, onValueSelected = {}, onDismissRequest = {}) } - onNodeWithContentDescription("Original color").assert(SemanticsMatcher.keyNotDefined(SemanticsActions.OnClick)) + onNodeWithContentDescription("Original color") + .assert(SemanticsMatcher.expectValue(SemanticsProperties.Role, Role.Button)) + .assertIsNotEnabled() sliderNamed("Hue").performSemanticsAction(SemanticsActions.SetProgress) { it(0.5f) } - onNodeWithContentDescription("Original color").assert(SemanticsMatcher.keyIsDefined(SemanticsActions.OnClick)) + onNodeWithContentDescription("Original color").assertIsEnabled() + } + + @Test + fun aHeaderToldItIsDisabledRestoresNothing() = runComposeUiTest { + var selected: ColorValue? = null + setContent { + ColorPickerDialog( + initialValue = teal, + onValueSelected = { selected = it }, + onDismissRequest = {}, + header = { ColorPickerDialogDefaults.Header(state, enabled = false) }, + ) + } + sliderNamed("Hue").performSemanticsAction(SemanticsActions.SetProgress) { it(0.5f) } + onNodeWithContentDescription("Original color").assertIsNotEnabled().performClick() + onNodeWithText("OK").performClick() + assertNotEquals(teal, selected) } @Test From cf667ad6dbb689b34dcef11de1b70bbec5e5f5ef Mon Sep 17 00:00:00 2001 From: Illia Achour Date: Sat, 26 Sep 2026 20:48:29 -0400 Subject: [PATCH 2/4] Announce the space menu as a list of choices Beyond five spaces the switcher is a button that opens a menu. A screen reader heard a button named after the space shown, then menu items with no sign of which one was chosen. The button is a drop-down list and the items are radio buttons in one selectable group, as the segmented row's already are. --- .../material3/ColorPickerDialogDefaults.kt | 14 +++++++++--- .../material3/ColorPickerDialogTest.kt | 22 +++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/colorpicker-material3/src/commonMain/kotlin/codes/side/colorpicker/material3/ColorPickerDialogDefaults.kt b/colorpicker-material3/src/commonMain/kotlin/codes/side/colorpicker/material3/ColorPickerDialogDefaults.kt index 30fa062b..80ce49a4 100644 --- a/colorpicker-material3/src/commonMain/kotlin/codes/side/colorpicker/material3/ColorPickerDialogDefaults.kt +++ b/colorpicker-material3/src/commonMain/kotlin/codes/side/colorpicker/material3/ColorPickerDialogDefaults.kt @@ -8,6 +8,7 @@ import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width +import androidx.compose.foundation.selection.selectableGroup import androidx.compose.material3.ButtonDefaults import androidx.compose.material3.DropdownMenu import androidx.compose.material3.DropdownMenuItem @@ -26,6 +27,8 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Path +import androidx.compose.ui.semantics.Role +import androidx.compose.ui.semantics.role import androidx.compose.ui.semantics.selected import androidx.compose.ui.semantics.semantics import androidx.compose.ui.text.font.FontFamily @@ -149,12 +152,14 @@ public object ColorPickerDialogDefaults { private fun SpaceMenu(state: ColorPickerDialogState, modifier: Modifier, enabled: Boolean) { var expanded by remember { mutableStateOf(false) } Box(modifier) { - OutlinedButton(onClick = { expanded = true }, enabled = enabled) { + // A screen reader hears a list to choose from, not a button named after the space shown. + OutlinedButton(onClick = { expanded = true }, modifier = Modifier.semantics { role = Role.DropdownList }, enabled = enabled) { Text(ColorPickerStrings.current.spaceName(state.space), maxLines = 1) Spacer(Modifier.width(ButtonDefaults.IconSpacing)) DropdownArrow(Modifier.size(ButtonDefaults.IconSize)) } - DropdownMenu(expanded = expanded && enabled, onDismissRequest = { expanded = false }) { + // One choice among the spaces, as the row of segmented buttons is. + DropdownMenu(expanded = expanded && enabled, onDismissRequest = { expanded = false }, modifier = Modifier.selectableGroup()) { for (space in state.spaces) { DropdownMenuItem( text = { Text(ColorPickerStrings.current.spaceName(space)) }, @@ -162,7 +167,10 @@ private fun SpaceMenu(state: ColorPickerDialogState, modifier: Modifier, enabled state.space = space expanded = false }, - modifier = Modifier.semantics { selected = space == state.space }, + modifier = Modifier.semantics { + role = Role.RadioButton + selected = space == state.space + }, ) } } diff --git a/colorpicker-material3/src/jvmTest/kotlin/codes/side/colorpicker/material3/ColorPickerDialogTest.kt b/colorpicker-material3/src/jvmTest/kotlin/codes/side/colorpicker/material3/ColorPickerDialogTest.kt index 7dfec1ef..2c6fc3ad 100644 --- a/colorpicker-material3/src/jvmTest/kotlin/codes/side/colorpicker/material3/ColorPickerDialogTest.kt +++ b/colorpicker-material3/src/jvmTest/kotlin/codes/side/colorpicker/material3/ColorPickerDialogTest.kt @@ -18,6 +18,7 @@ import androidx.compose.ui.test.assertIsEnabled import androidx.compose.ui.test.assertIsNotEnabled import androidx.compose.ui.test.assertIsNotSelected import androidx.compose.ui.test.assertIsSelected +import androidx.compose.ui.test.hasText import androidx.compose.ui.test.onNodeWithContentDescription import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.performClick @@ -262,6 +263,27 @@ class ColorPickerDialogTest { onNodeWithText("Okhsl").assertDoesNotExist() } + @Test + fun theMenuIsAListOfRadioButtons() = runComposeUiTest { + val spaces = listOf(Okhsl, OkLch, Oklab, Hsv, Hsl, Lab, Lch) + setContent { ColorPickerDialog(initialValue = teal, onValueSelected = {}, onDismissRequest = {}, spaces = spaces) } + onNodeWithText("Okhsl") + .assert(SemanticsMatcher.expectValue(SemanticsProperties.Role, Role.DropdownList)) + .performClick() + onAllNodes(radioButton).assertCountEquals(7) + onNode(radioButton and hasText("Okhsl")).assertIsSelected() + onNode(radioButton and hasText("LCH")).assertIsNotSelected() + onAllNodes(SemanticsMatcher.keyIsDefined(SemanticsProperties.SelectableGroup)).assertCountEquals(1) + } + + @Test + fun aDisabledMenuDoesNotOpen() = runComposeUiTest { + val spaces = listOf(Okhsl, OkLch, Oklab, Hsv, Hsl, Lab, Lch) + setContent { ColorPickerDialog(initialValue = teal, onValueSelected = {}, onDismissRequest = {}, spaces = spaces, enabled = false) } + onNodeWithText("Okhsl").assertIsNotEnabled().performClick() + onAllNodes(radioButton).assertCountEquals(0) + } + @Test fun theDialogIsAnnouncedByItsTitle() = runComposeUiTest { setContent { ColorPickerDialog(initialValue = teal, onValueSelected = {}, onDismissRequest = {}) } From cf62069fbc84530b0af5199ce527009c779c9de8 Mon Sep 17 00:00:00 2001 From: Illia Achour Date: Sat, 26 Sep 2026 20:49:50 -0400 Subject: [PATCH 3/4] Release focus held by the dialog's hidden stacked form The dialog's content stays composed in its stacked form while laid out side by side, only to measure it. A slider there that held keyboard focus when the content flipped, as it does when a window is resized, kept it while not placed: nothing on screen showed where focus was, and the next key moved a slider that was not drawn. The content clears that focus once it lays out side by side, and only that focus. --- .../BasicColorPickerDialogContent.kt | 13 ++++++ .../BasicColorPickerDialogContentTest.kt | 40 +++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/colorpicker-foundation/src/commonMain/kotlin/codes/side/colorpicker/foundation/BasicColorPickerDialogContent.kt b/colorpicker-foundation/src/commonMain/kotlin/codes/side/colorpicker/foundation/BasicColorPickerDialogContent.kt index 5c23bdba..9ae4b286 100644 --- a/colorpicker-foundation/src/commonMain/kotlin/codes/side/colorpicker/foundation/BasicColorPickerDialogContent.kt +++ b/colorpicker-foundation/src/commonMain/kotlin/codes/side/colorpicker/foundation/BasicColorPickerDialogContent.kt @@ -1,5 +1,6 @@ package codes.side.colorpicker.foundation +import androidx.compose.foundation.focusGroup import androidx.compose.foundation.gestures.Orientation import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box @@ -9,12 +10,15 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll import androidx.compose.runtime.Composable +import androidx.compose.runtime.SideEffect import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.snapshots.Snapshot import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.focus.onFocusChanged import androidx.compose.ui.layout.SubcomposeLayout +import androidx.compose.ui.platform.LocalFocusManager import androidx.compose.ui.semantics.clearAndSetSemantics import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp @@ -69,6 +73,13 @@ public fun BasicColorPickerDialogContent( // reads to keep out of the semantics tree: a composed node that is never placed is still in it, and a // screen reader would find every slider twice. val sideBySide = remember { mutableStateOf(false) } + // Whether a part of the stacked form holds keyboard focus. Laid out side by side, that part is not placed and + // nothing shows where focus is, so it is let go. + val stackedHasFocus = remember { mutableStateOf(false) } + if (sideBySide.value && stackedHasFocus.value) { + val focusManager = LocalFocusManager.current + SideEffect { focusManager.clearFocus(force = true) } + } val stackedScroll = rememberScrollState() val sideBySideScroll = rememberScrollState() // Built here rather than in the measure block, so every measure pass hands SubcomposeLayout the same content, @@ -77,6 +88,8 @@ public fun BasicColorPickerDialogContent( StackedParts( modifier = Modifier .then(if (sideBySide.value) Modifier.clearAndSetSemantics {} else Modifier) + .onFocusChanged { stackedHasFocus.value = it.hasFocus } + .focusGroup() .verticalScroll(stackedScroll), header = header, spaceSwitcher = spaceSwitcher, diff --git a/colorpicker-foundation/src/jvmTest/kotlin/codes/side/colorpicker/foundation/BasicColorPickerDialogContentTest.kt b/colorpicker-foundation/src/jvmTest/kotlin/codes/side/colorpicker/foundation/BasicColorPickerDialogContentTest.kt index ccb33ccf..a1e4f4c2 100644 --- a/colorpicker-foundation/src/jvmTest/kotlin/codes/side/colorpicker/foundation/BasicColorPickerDialogContentTest.kt +++ b/colorpicker-foundation/src/jvmTest/kotlin/codes/side/colorpicker/foundation/BasicColorPickerDialogContentTest.kt @@ -27,6 +27,7 @@ import androidx.compose.ui.test.SemanticsMatcher import androidx.compose.ui.test.assert import androidx.compose.ui.test.assertCountEquals import androidx.compose.ui.test.assertHeightIsEqualTo +import androidx.compose.ui.test.assertIsFocused import androidx.compose.ui.test.assertWidthIsEqualTo import androidx.compose.ui.test.getBoundsInRoot import androidx.compose.ui.test.onAllNodesWithTag @@ -43,6 +44,7 @@ import codes.side.color.Srgb import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFalse +import kotlin.test.assertTrue @OptIn(ExperimentalTestApi::class) class BasicColorPickerDialogContentTest { @@ -194,6 +196,44 @@ class BasicColorPickerDialogContentTest { assertFalse(hiddenFocused, "focus reached the stacked form, which is not shown") } + @Test + fun theStackedFormLetsGoOfFocusWhenItStopsBeingShown() = runComposeUiTest { + var tall by mutableStateOf(false) + var stackedFocused = false + setContent { + Content(width = 600.dp, height = 300.dp) { orientation -> + val stacked = orientation == Orientation.Vertical + Box( + Modifier + .testTag("picker $orientation") + .fillMaxWidth() + .height(if (!stacked) 200.dp else if (tall) 400.dp else 100.dp) + .onFocusChanged { if (stacked) stackedFocused = it.isFocused } + .focusable(), + ) + } + } + onNodeWithTag("picker ${Orientation.Vertical}").requestFocus() + assertTrue(stackedFocused) + tall = true + waitForIdle() + onNodeWithTag("picker ${Orientation.Horizontal}").assertExists() + assertFalse(stackedFocused, "the stacked form, no longer shown, still holds focus") + } + + @Test + fun focusInTheFormShownIsKept() = runComposeUiTest { + setContent { + Content(width = 600.dp, height = 300.dp) { orientation -> + val height = if (orientation == Orientation.Vertical) 400.dp else 200.dp + Box(Modifier.testTag("picker $orientation").fillMaxWidth().height(height).focusable()) + } + } + onNodeWithTag("picker ${Orientation.Horizontal}").requestFocus() + waitForIdle() + onNodeWithTag("picker ${Orientation.Horizontal}").assertIsFocused() + } + @Test fun itStacksAgainOnceThatFits() = runComposeUiTest { var tall by mutableStateOf(true) From 5b280329988a88c4ac769800cbf85aff3889cdae Mon Sep 17 00:00:00 2001 From: Illia Achour Date: Sat, 26 Sep 2026 20:51:44 -0400 Subject: [PATCH 4/4] Document what names the dialog and what it throws An app that replaces the title slot still has the dialog announced by ColorPickerStrings.dialogTitle, and needs to know that and the two ways to change it: provided strings, or a paneTitle in the modifier. The last works only because the library sets its own inside the caller's modifier, which a test and a comment now hold in place. An empty spaces with the default initialSpace throws NoSuchElementException from spaces.first() in the default expression, which the KDoc says beside the IllegalArgumentException cases. --- .../foundation/ColorPickerDialogState.kt | 4 ++++ .../material3/ColorPickerDialog.kt | 7 +++++- .../material3/ColorPickerDialogTest.kt | 24 +++++++++++++++++++ .../material3/StringsInComponentsTest.kt | 10 ++++++++ 4 files changed, 44 insertions(+), 1 deletion(-) diff --git a/colorpicker-foundation/src/commonMain/kotlin/codes/side/colorpicker/foundation/ColorPickerDialogState.kt b/colorpicker-foundation/src/commonMain/kotlin/codes/side/colorpicker/foundation/ColorPickerDialogState.kt index b5cba04e..ffd0168a 100644 --- a/colorpicker-foundation/src/commonMain/kotlin/codes/side/colorpicker/foundation/ColorPickerDialogState.kt +++ b/colorpicker-foundation/src/commonMain/kotlin/codes/side/colorpicker/foundation/ColorPickerDialogState.kt @@ -38,6 +38,7 @@ public class ColorPickerDialogState internal constructor( * @param spaces the spaces the dialog offers, in the order a switcher lists them. * @param initialSpace [initialValue]'s own space when [spaces] holds it, else the first of [spaces]. * @throws IllegalArgumentException if [spaces] lists a space twice or does not hold [initialSpace]. + * @throws NoSuchElementException if [spaces] is empty and [initialSpace] is left to its default. */ public constructor( initialValue: ColorValue, @@ -105,6 +106,9 @@ public class ColorPickerDialogState internal constructor( * them. A different [initialValue] or [spaces] starts the state over. * * The saver knows every space in [spaces] and [initialValue]'s own. + * + * @throws IllegalArgumentException if [spaces] lists a space twice or does not hold [initialSpace]. + * @throws NoSuchElementException if [spaces] is empty and [initialSpace] is left to its default. */ @Composable public fun rememberColorPickerDialogState( diff --git a/colorpicker-material3/src/commonMain/kotlin/codes/side/colorpicker/material3/ColorPickerDialog.kt b/colorpicker-material3/src/commonMain/kotlin/codes/side/colorpicker/material3/ColorPickerDialog.kt index b160a15a..59183ee4 100644 --- a/colorpicker-material3/src/commonMain/kotlin/codes/side/colorpicker/material3/ColorPickerDialog.kt +++ b/colorpicker-material3/src/commonMain/kotlin/codes/side/colorpicker/material3/ColorPickerDialog.kt @@ -61,7 +61,9 @@ public sealed interface ColorPickerDialogScope { * [ColorPickerTheme]. The body is laid out as [BasicColorPickerDialogContent] lays it out: with the plane * beside the sliders when the dialog is too short to stack them and wide enough not to. * - * A screen reader announces the dialog by [ColorPickerStrings.dialogTitle], "Select color". + * A screen reader announces the dialog by [ColorPickerStrings.dialogTitle], "Select color", whatever the [title] + * slot shows. Strings provided with `ProvideColorPickerStrings` change it, and so does a `paneTitle` set in + * [modifier]. * * @param onValueSelected called by [ColorPickerDialogScope.confirm] with [ColorPickerDialogState.result]: * exactly [initialValue] when nothing was edited or the original was restored; otherwise the color as last @@ -91,6 +93,7 @@ public sealed interface ColorPickerDialogScope { * are colored by default. * @param alphaSlider slot for the alpha slider; `null` leaves it out. * @throws IllegalArgumentException if [spaces] lists a space twice or does not hold [initialSpace]. + * @throws NoSuchElementException if [spaces] is empty and [initialSpace] is left to its default. */ @Composable public fun ColorPickerDialog( @@ -150,6 +153,7 @@ public fun ColorPickerDialog( * * @throws IllegalArgumentException for [Color.Unspecified] and Compose's HDR spaces, which [toColorValue] * refuses, and if [spaces] lists a space twice or does not hold [initialSpace]. + * @throws NoSuchElementException if [spaces] is empty and [initialSpace] is left to its default. */ @Composable public fun ColorPickerDialog( @@ -238,6 +242,7 @@ private fun DialogBody( AlertDialog( onDismissRequest = onDismissRequest, confirmButton = { scope.confirmButton() }, + // Inside the caller's modifier, so a paneTitle set there wins. modifier = modifier.semantics { this.paneTitle = paneTitle }, dismissButton = dismissButton?.let { slot -> { scope.slot() } }, title = title?.let { slot -> { scope.slot() } }, diff --git a/colorpicker-material3/src/jvmTest/kotlin/codes/side/colorpicker/material3/ColorPickerDialogTest.kt b/colorpicker-material3/src/jvmTest/kotlin/codes/side/colorpicker/material3/ColorPickerDialogTest.kt index 2c6fc3ad..f86fce5d 100644 --- a/colorpicker-material3/src/jvmTest/kotlin/codes/side/colorpicker/material3/ColorPickerDialogTest.kt +++ b/colorpicker-material3/src/jvmTest/kotlin/codes/side/colorpicker/material3/ColorPickerDialogTest.kt @@ -5,11 +5,14 @@ import androidx.compose.material3.TextButton import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue +import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.semantics.Role import androidx.compose.ui.semantics.SemanticsActions import androidx.compose.ui.semantics.SemanticsProperties import androidx.compose.ui.semantics.getOrNull +import androidx.compose.ui.semantics.paneTitle +import androidx.compose.ui.semantics.semantics import androidx.compose.ui.test.ExperimentalTestApi import androidx.compose.ui.test.SemanticsMatcher import androidx.compose.ui.test.assert @@ -291,6 +294,27 @@ class ColorPickerDialogTest { onAllNodes(SemanticsMatcher.expectValue(SemanticsProperties.PaneTitle, "Dialog")).assertCountEquals(0) } + @Test + fun aReplacedTitleLeavesTheDialogsName() = runComposeUiTest { + setContent { ColorPickerDialog(initialValue = teal, onValueSelected = {}, onDismissRequest = {}, title = { Text("Brand color") }) } + onNode(SemanticsMatcher.expectValue(SemanticsProperties.PaneTitle, "Select color")).assertExists() + } + + @Test + fun aPaneTitleInTheModifierRenamesTheDialog() = runComposeUiTest { + setContent { + ColorPickerDialog( + initialValue = teal, + onValueSelected = {}, + onDismissRequest = {}, + modifier = Modifier.semantics { paneTitle = "Brand color" }, + title = { Text("Brand color") }, + ) + } + onNode(SemanticsMatcher.expectValue(SemanticsProperties.PaneTitle, "Brand color")).assertExists() + onAllNodes(SemanticsMatcher.expectValue(SemanticsProperties.PaneTitle, "Select color")).assertCountEquals(0) + } + @Test fun theHeaderShowsTheColorInHex() = runComposeUiTest { setContent { ColorPickerDialog(initialValue = Srgb(0x33 / 255.0, 0x66 / 255.0, 0x99 / 255.0), onValueSelected = {}, onDismissRequest = {}) } diff --git a/colorpicker-material3/src/jvmTest/kotlin/codes/side/colorpicker/material3/StringsInComponentsTest.kt b/colorpicker-material3/src/jvmTest/kotlin/codes/side/colorpicker/material3/StringsInComponentsTest.kt index c6732278..0c75f212 100644 --- a/colorpicker-material3/src/jvmTest/kotlin/codes/side/colorpicker/material3/StringsInComponentsTest.kt +++ b/colorpicker-material3/src/jvmTest/kotlin/codes/side/colorpicker/material3/StringsInComponentsTest.kt @@ -113,6 +113,16 @@ class StringsInComponentsTest { onNodeWithText("Cancel").assertExists() } + @Test + fun providedStringsNameTheDialogWithoutATitle() = runComposeUiTest { + setContent { + ProvideColorPickerStrings(Custom) { + ColorPickerDialog(initialValue = Hsl(200.0, 40.0, 50.0), onValueSelected = {}, onDismissRequest = {}, title = null) + } + } + onNode(SemanticsMatcher.expectValue(SemanticsProperties.PaneTitle, "Choose")).assertExists() + } + @Test fun theDialogReadsSelectColorAndOkByDefault() = runComposeUiTest { setContent { ColorPickerDialog(initialValue = Hsl(200.0, 40.0, 50.0), onValueSelected = {}, onDismissRequest = {}) }