Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ internal class ComposeAccessible(
}

override fun getAccessibleName(): String? {
return text?.toString()
return semanticsConfig.getOrNull(SemanticsProperties.ContentDescription)?.mergeText()
?: semanticsConfig.getOrNull(SemanticsProperties.Text)?.mergeText()
}

override fun getAccessibleDescription(): String? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,41 @@ class AccessibilityTest {
.isEqualTo(AccessibleRole.PUSH_BUTTON)
}

@Test
fun textFieldAccessibleNameUsesContentDescription() = runDesktopA11yTest {
test.setContent {
BasicTextField(
value = "typed text",
onValueChange = { },
modifier = Modifier
.testTag("textFieldWithLabel")
.semantics {
contentDescription = "Email"
}
)
}

val context = test.onNodeWithTag("textFieldWithLabel").fetchAccessible().accessibleContext
assertThat(context?.accessibleName).isEqualTo("Email")
assertThat(context?.accessibleDescription).isEqualTo("Email")
}

@Test
fun textFieldAccessibleNameIsNullWithoutContentDescription() = runDesktopA11yTest {
test.setContent {
BasicTextField(
value = "typed text",
onValueChange = { },
modifier = Modifier.testTag("textFieldNoLabel")
)
}

val context = test.onNodeWithTag("textFieldNoLabel").fetchAccessible().accessibleContext
// TextField without contentDescription should have null accessibleName.
// The text content is available through the AccessibleText interface.
assertThat(context?.accessibleName).isEqualTo(null)
}

private fun verifyA11yHierarchyFromAccessible(
window: Window,
@Suppress("SameParameterValue") accessibleName: String
Expand Down
Loading