Skip to content

Commit

Permalink
Desktop. Don't use AccessibleRole.PANEL for root/unknown nodes (fixes…
Browse files Browse the repository at this point in the history
… issues on Windows) (#885)

This fixes issues on Windows:

1. Windows pronounced "Panel unavailable" at start
2. When we focus on Switch or Box(Modifier.clickable), there was
"Panel0" pronounced. Now it says nothing.
3. After merging
#881, we
refocus the main component. This leads to pronouncing the window title,
now it says nothing, as the accessible root node is unknown

on macOs it changes one thing:
1. When we focus on Switch or Box(Modifier.clickable), now it prounonces
that we in scroll area (if we in scroll area). It also pronounces it for
other compnents like Button/Text

## Testing
Manually with accessibility enabled in run1 (Windows, macOs)
  • Loading branch information
igordmn committed Oct 20, 2023
1 parent 2e89e0c commit 8748d3e
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ internal class ComposeAccessible(
val progressBarRangeInfo
get() = semanticsNode.config.getOrNull(SemanticsProperties.ProgressBarRangeInfo)

val isContainer
@Suppress("DEPRECATION")
get() = semanticsNode.config.getOrNull(SemanticsProperties.IsContainer)

val isTraversalGroup
get() = semanticsNode.config.getOrNull(SemanticsProperties.IsTraversalGroup)

private fun makeScrollbarChild(
vertical: Boolean
): Accessible {
Expand Down Expand Up @@ -402,7 +409,9 @@ internal class ComposeAccessible(
setText != null -> AccessibleRole.TEXT
text != null -> AccessibleRole.LABEL
progressBarRangeInfo != null -> AccessibleRole.PROGRESS_BAR
else -> AccessibleRole.PANEL
isContainer != null -> AccessibleRole.GROUP_BOX
isTraversalGroup != null -> AccessibleRole.GROUP_BOX
else -> AccessibleRole.UNKNOWN
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ internal class ComposeSceneAccessible(
}

override fun getAccessibleRole(): AccessibleRole {
return AccessibleRole.PANEL
return AccessibleRole.UNKNOWN
}

override fun getAccessibleStateSet(): AccessibleStateSet {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package androidx.compose.ui.platform

import androidx.compose.foundation.layout.Box
import androidx.compose.material.Button
import androidx.compose.material.LinearProgressIndicator
import androidx.compose.material.Tab
Expand All @@ -25,6 +26,8 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.assertThat
import androidx.compose.ui.isEqualTo
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.semantics.isContainer
import androidx.compose.ui.semantics.isTraversalGroup
import androidx.compose.ui.semantics.role
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.test.SemanticsNodeInteraction
Expand Down Expand Up @@ -126,9 +129,49 @@ class AccessibilityTest {
}
}

@Test
fun boxHasUnknownRole() {
rule.setContent {
Box(Modifier.testTag("box"))
}

rule.onNodeWithTag("box").apply {
val context = ComposeAccessible(fetchSemanticsNode()).accessibleContext!!
assertThat(context.accessibleRole).isEqualTo(AccessibleRole.UNKNOWN)
}
}

@Suppress("DEPRECATION")
@Test
fun containerHasGroupRole() {
rule.setContent {
Box(Modifier.testTag("box").semantics {
isContainer = true
})
}

rule.onNodeWithTag("box").apply {
val context = ComposeAccessible(fetchSemanticsNode()).accessibleContext!!
assertThat(context.accessibleRole).isEqualTo(AccessibleRole.GROUP_BOX)
}
}

@Test
fun traversalGroupHasGroupRole() {
rule.setContent {
Box(Modifier.testTag("box").semantics {
isTraversalGroup = true
})
}

rule.onNodeWithTag("box").apply {
val context = ComposeAccessible(fetchSemanticsNode()).accessibleContext!!
assertThat(context.accessibleRole).isEqualTo(AccessibleRole.GROUP_BOX)
}
}

private fun SemanticsNodeInteraction.assertHasAccessibleRole(role: AccessibleRole) {
val accessibleContext = ComposeAccessible(fetchSemanticsNode()).accessibleContext!!
assertThat(accessibleContext.accessibleRole).isEqualTo(role)
}

}

0 comments on commit 8748d3e

Please sign in to comment.