Hey folks :wave: I have a text that I would like t...
# compose-android
s
Hey folks 👋 I have a text that I would like to skip from talkback. If I use
clearAndSetSemantics{}
on this node, it is skipped but all other semantic information is also removed and I cannot assert the text content in a test. While this component is not useful for talkback, I'd still like to assert the content in a UI test. What's the recommended way to handle this ?
n
You can achieve the desired behavior by using the
clearAndSetSemantics
modifier to set a test tag while also ensuring the text is not read by TalkBack. This way, you can still assert the content in a test.
@Composablefun MyComposable() { Column { Text( text = "This text should be skipped by TalkBack", modifier = Modifier .clearAndSetSemantics { testTag = "skippedText" // Set the test tag here// Prevent TalkBack from reading this text } ) Text( text = "This text is visible to TalkBack" ) } }