commit ec25572b4fd4233c39a7b30e476dc816fe5764a6 parent 2f7c13aca84bae7e2196ce73b02d41728a24427b Author: Moyin <madeyemi@mozilla.com> Date: Tue, 2 Dec 2025 17:48:37 +0000 Bug 1993691 - Fix unified search elements announced twice by Talkback r=android-reviewers,petru Differential Revision: https://phabricator.services.mozilla.com/D274745 Diffstat:
3 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/mobile/android/android-components/components/compose/browser-toolbar/src/main/java/mozilla/components/compose/browser/toolbar/ui/Origin.kt b/mobile/android/android-components/components/compose/browser-toolbar/src/main/java/mozilla/components/compose/browser/toolbar/ui/Origin.kt @@ -120,13 +120,14 @@ internal fun Origin( else -> url } } + val contentDescription: String = getContentDescription(urlToShow, hint, title) CompositionLocalProvider(LocalIndication provides NoRippleIndication) { Box( contentAlignment = Alignment.CenterStart, modifier = modifier .clearAndSetSemantics { - this.contentDescription = "${title ?: ""} $urlToShow. $hint" + this.contentDescription = contentDescription } .clickable( enabled = onClick != null && !shouldReactToLongClicks, @@ -259,6 +260,16 @@ private fun TextGravity.toTextTruncationDirection() = when (this) { TEXT_GRAVITY_END -> START } +@Composable +private fun getContentDescription(urlToShow: CharSequence, hint: String, title: String?) = + remember(urlToShow) { + if (urlToShow == hint) { + hint + } else { + "${title ?: ""} $urlToShow. $hint" + } + } + /** * Custom indication disabling click ripples. */ diff --git a/mobile/android/android-components/components/compose/browser-toolbar/src/main/java/mozilla/components/compose/browser/toolbar/ui/PopupToMenuItemsMapper.kt b/mobile/android/android-components/components/compose/browser-toolbar/src/main/java/mozilla/components/compose/browser/toolbar/ui/PopupToMenuItemsMapper.kt @@ -35,8 +35,8 @@ import androidx.compose.ui.platform.LocalView import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.semantics.Role +import androidx.compose.ui.semantics.clearAndSetSemantics import androidx.compose.ui.semantics.contentDescription -import androidx.compose.ui.semantics.semantics import androidx.compose.ui.unit.dp import com.google.accompanist.drawablepainter.rememberDrawablePainter import mozilla.components.compose.base.modifier.thenConditional @@ -92,7 +92,7 @@ internal fun menuItemComposable( }, ), ) { source.onClick != null } - .semantics(mergeDescendants = true) { + .clearAndSetSemantics { this.contentDescription = contentDescription } .fillMaxWidth() diff --git a/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/ui/robots/NavigationToolbarRobot.kt b/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/ui/robots/NavigationToolbarRobot.kt @@ -182,7 +182,7 @@ class NavigationToolbarRobot { fun verifySearchBarPlaceholderWithComposableToolbar(composeTestRule: ComposeTestRule) { Log.i(TAG, "verifySearchBarPlaceholderWithComposableToolbar: Trying to verify that the search bar place holder is \"Search or enter address\"") - composeTestRule.onNodeWithTag(ADDRESSBAR_URL_BOX).assert(hasContentDescription(" Search or enter address. Search or enter address")) + composeTestRule.onNodeWithTag(ADDRESSBAR_URL_BOX).assert(hasContentDescription("Search or enter address")) Log.i(TAG, "verifySearchBarPlaceholderWithComposableToolbar: Verified that the search bar place holder is \"Search or enter address\"") }