Expose formatting toggle state to accessibility services

FormattingOption used clearAndSetSemantics with only a contentDescription,
so the Bold/Italic/Underline toggle buttons never exposed whether they
were currently active to TalkBack. Add a stateDescription reflecting the
selected/unselected state alongside the existing contentDescription.

New a11y_active / a11y_inactive strings added to temporary.xml for
Localazy import.
This commit is contained in:
Jürgen Wischer
2026-07-15 22:05:04 +02:00
parent 3bb7fe97e6
commit a6aa29f375
2 changed files with 14 additions and 0 deletions
@@ -23,14 +23,17 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.clearAndSetSemantics import androidx.compose.ui.semantics.clearAndSetSemantics
import androidx.compose.ui.semantics.contentDescription import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.stateDescription
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import io.element.android.compound.theme.ElementTheme import io.element.android.compound.theme.ElementTheme
import io.element.android.compound.tokens.generated.CompoundIcons import io.element.android.compound.tokens.generated.CompoundIcons
import io.element.android.libraries.designsystem.preview.ElementPreview import io.element.android.libraries.designsystem.preview.ElementPreview
import io.element.android.libraries.designsystem.preview.PreviewsDayNight import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import io.element.android.libraries.designsystem.theme.components.Icon import io.element.android.libraries.designsystem.theme.components.Icon
import io.element.android.libraries.ui.strings.CommonStrings
@Composable @Composable
internal fun FormattingOption( internal fun FormattingOption(
@@ -52,6 +55,8 @@ internal fun FormattingOption(
FormattingOptionState.Default -> ElementTheme.colors.iconSecondary FormattingOptionState.Default -> ElementTheme.colors.iconSecondary
FormattingOptionState.Disabled -> ElementTheme.colors.iconDisabled FormattingOptionState.Disabled -> ElementTheme.colors.iconDisabled
} }
val activeStateDescription = stringResource(CommonStrings.a11y_active)
val inactiveStateDescription = stringResource(CommonStrings.a11y_inactive)
Box( Box(
modifier = modifier modifier = modifier
.clickable( .clickable(
@@ -77,6 +82,13 @@ internal fun FormattingOption(
) )
.clearAndSetSemantics { .clearAndSetSemantics {
this.contentDescription = contentDescription this.contentDescription = contentDescription
if (toggleable) {
this.stateDescription = if (state == FormattingOptionState.Selected) {
activeStateDescription
} else {
inactiveStateDescription
}
}
} }
) { ) {
Box( Box(
@@ -10,4 +10,6 @@
<string name="a11y_jump_to_unread_messages">"Jump to first unread message"</string> <string name="a11y_jump_to_unread_messages">"Jump to first unread message"</string>
<string name="screen_local_network_opt_in_title">Allow access to local network</string> <string name="screen_local_network_opt_in_title">Allow access to local network</string>
<string name="screen_local_network_opt_in_subtitle">Your homeserver is on your local network. To connect, Element needs permission to reach other devices on this network.</string> <string name="screen_local_network_opt_in_subtitle">Your homeserver is on your local network. To connect, Element needs permission to reach other devices on this network.</string>
<string name="a11y_active">Active</string>
<string name="a11y_inactive">Inactive</string>
</resources> </resources>