Modern Apps git

← Modern-Apps.git

library/ui: shared-text fields no longer drop their supporting/error text

Commit
dc3a6fbb163dfd54ca4c57b67d5559ca3997d02a
Author
Vayun Mathur <[email protected]>
When
2026-12-01 09:53 UTC (5 days ago)
Parents
bd53040
LabeledTextField's sharedTextKey branch delegated to
SharedTextLabeledField (the BasicTextField+DecorationBox
rebuild used for the shared-element morph), which never
accepted supportingText: a morphing field rendered with
isError=true silently lost both the 'Must not be empty' text
and the accessibility error association that the plain
branch provides (and that A11ySemanticsSliceTest pins).
Only FormDetailGroup also reaches the shared branch, at
isError=false with no supporting text, so the drop was
invisible there.

The shared branch now forwards supportingText to
DecorationBox and applies the same semantics error() when
isError && supportingText != null; no API change. Two
regression tests failed pre-fix on the missing text.
Scaffold, messenger, theme and dropdowns were audited and
cleared. Verified: :library:ui:testDebugUnitTest and
:library:ui:lint BUILD SUCCESSFUL (lint hints are
pre-existing MissingTranslation in strings.xml); ktlint
carries only its known backlog, with no new findings in the
changed files.

Diff

library/ui/src/main/java/com/vayunmathur/library/ui/FormComponents.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/FormComponents.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/FormComponents.ktindex 61e0a1ec02..f9aa3fbae4 100644--- a/library/ui/src/main/java/com/vayunmathur/library/ui/FormComponents.kt+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/FormComponents.kt@@ -95,6 +95,7 @@ fun LabeledTextField(             keyboardActions = keyboardActions,             visualTransformation = visualTransformation,             isError = isError,+            supportingText = supportingText,             placeholder = placeholder,             leadingIcon = leadingIcon,             trailingIcon = trailingIcon,@@ -149,15 +150,22 @@ private fun SharedTextLabeledField(     keyboardActions: KeyboardActions = KeyboardActions.Default,     visualTransformation: VisualTransformation,     isError: Boolean,+    supportingText: String? = null,     placeholder: String?,     leadingIcon: (@Composable () -> Unit)?,     trailingIcon: (@Composable () -> Unit)?, ) {     val interactionSource = remember { MutableInteractionSource() }+    val fieldModifier =+        if (isError && supportingText != null) {+            modifier.semantics { error(supportingText) }+        } else {+            modifier+        }     BasicTextField(         value = value,         onValueChange = onValueChange,-        modifier = modifier,+        modifier = fieldModifier,         enabled = enabled,         readOnly = readOnly,         textStyle = LocalTextStyle.current.copy(color = MaterialTheme.colorScheme.onSurface),@@ -182,6 +190,7 @@ private fun SharedTextLabeledField(             placeholder = placeholder?.let { { Text(it) } },             leadingIcon = leadingIcon,             trailingIcon = trailingIcon,+            supportingText = supportingText?.let { { Text(it) } },         )     } }
library/ui/src/test/java/com/vayunmathur/library/ui/LabeledFieldSharedSupportingTextTest.kt
diff --git a/library/ui/src/test/java/com/vayunmathur/library/ui/LabeledFieldSharedSupportingTextTest.kt b/library/ui/src/test/java/com/vayunmathur/library/ui/LabeledFieldSharedSupportingTextTest.ktnew file mode 100644index 0000000000..26237872a9--- /dev/null+++ b/library/ui/src/test/java/com/vayunmathur/library/ui/LabeledFieldSharedSupportingTextTest.kt@@ -0,0 +1,55 @@+package com.vayunmathur.library.ui++import androidx.compose.ui.semantics.SemanticsProperties+import androidx.compose.ui.test.SemanticsMatcher+import androidx.compose.ui.test.assert+import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onNodeWithText+import org.junit.Rule+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner+import kotlin.test.Test++/**+ * Regression: the shared-text branch of [LabeledTextField] must honour+ * `supportingText` (and the error semantics tied to it) exactly like the+ * plain branch does.+ */+@RunWith(RobolectricTestRunner::class)+class LabeledFieldSharedSupportingTextTest {+    @get:Rule+    val rule = createComposeRule()++    @Test+    fun sharedTextFieldShowsSupportingText() {+        rule.setContent {+            LabeledTextField(+                value = "bad",+                onValueChange = {},+                label = "Field",+                supportingText = "A helpful hint",+                sharedTextKey = "shared-supporting-key",+            )+        }+        rule.onNodeWithText("A helpful hint").assertIsDisplayed()+    }++    @Test+    fun sharedTextFieldAssociatesErrorWhenErrorWithSupportingText() {+        rule.setContent {+            LabeledTextField(+                value = "bad",+                onValueChange = {},+                label = "Field",+                isError = true,+                supportingText = "Must not be empty",+                sharedTextKey = "shared-error-key",+            )+        }+        rule.onNodeWithText("Must not be empty").assertIsDisplayed()+        rule+            .onNode(SemanticsMatcher.keyIsDefined(SemanticsProperties.Error))+            .assert(SemanticsMatcher.expectValue(SemanticsProperties.Error, "Must not be empty"))+    }+}