mirror of
https://github.com/bitwarden/android.git
synced 2024-11-24 02:15:53 +03:00
Improve switch toggle semantics (#140)
This commit is contained in:
parent
f5619d1710
commit
3f742cc6df
3 changed files with 14 additions and 5 deletions
|
@ -16,6 +16,8 @@ import androidx.compose.runtime.remember
|
|||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.semantics.toggleableState
|
||||
import androidx.compose.ui.state.ToggleableState
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
|
@ -43,7 +45,9 @@ fun BitwardenSwitch(
|
|||
indication = rememberRipple(color = MaterialTheme.colorScheme.primary),
|
||||
onClick = { onCheckedChange?.invoke(!isChecked) },
|
||||
)
|
||||
.semantics(mergeDescendants = true) { }
|
||||
.semantics(mergeDescendants = true) {
|
||||
toggleableState = ToggleableState(isChecked)
|
||||
}
|
||||
.then(modifier),
|
||||
) {
|
||||
Switch(
|
||||
|
|
|
@ -17,6 +17,8 @@ import androidx.compose.ui.Alignment
|
|||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.semantics.contentDescription
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.semantics.toggleableState
|
||||
import androidx.compose.ui.state.ToggleableState
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.x8bit.bitwarden.ui.platform.theme.BitwardenTheme
|
||||
|
@ -50,6 +52,7 @@ fun BitwardenWideSwitch(
|
|||
onClick = { onCheckedChange?.invoke(!isChecked) },
|
||||
)
|
||||
.semantics(mergeDescendants = true) {
|
||||
toggleableState = ToggleableState(isChecked)
|
||||
if (contentDescription != null) {
|
||||
this.contentDescription = contentDescription
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@ import androidx.compose.ui.semantics.ProgressBarRangeInfo
|
|||
import androidx.compose.ui.semantics.SemanticsProperties
|
||||
import androidx.compose.ui.test.SemanticsMatcher.Companion.expectValue
|
||||
import androidx.compose.ui.test.assertIsDisplayed
|
||||
import androidx.compose.ui.test.assertIsOff
|
||||
import androidx.compose.ui.test.assertIsOn
|
||||
import androidx.compose.ui.test.filterToOne
|
||||
import androidx.compose.ui.test.hasContentDescription
|
||||
import androidx.compose.ui.test.hasProgressBarRangeInfo
|
||||
|
@ -156,22 +158,22 @@ class GeneratorScreenTest : BaseComposeTest() {
|
|||
composeTestRule
|
||||
.onNodeWithText("A—Z")
|
||||
.performScrollTo()
|
||||
.assertIsDisplayed()
|
||||
.assertIsOn()
|
||||
|
||||
composeTestRule
|
||||
.onNodeWithText("a—z")
|
||||
.performScrollTo()
|
||||
.assertIsDisplayed()
|
||||
.assertIsOn()
|
||||
|
||||
composeTestRule
|
||||
.onNodeWithText("0-9")
|
||||
.performScrollTo()
|
||||
.assertIsDisplayed()
|
||||
.assertIsOn()
|
||||
|
||||
composeTestRule
|
||||
.onNodeWithText("!@#$%^&*")
|
||||
.performScrollTo()
|
||||
.assertIsDisplayed()
|
||||
.assertIsOff()
|
||||
|
||||
composeTestRule
|
||||
.onNodeWithContentDescription("Minimum numbers, 1")
|
||||
|
|
Loading…
Reference in a new issue