Skip to content

Commit

Permalink
[#560] Group elements in a same vocalization
Browse files Browse the repository at this point in the history
  • Loading branch information
paulinea committed Aug 7, 2023
1 parent 75c4820 commit bcde27d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@ import androidx.compose.material.ExposedDropdownMenuBox
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.clearAndSetSemantics
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.stateDescription
import androidx.compose.ui.tooling.preview.PreviewParameter
import com.orange.ods.compose.component.OdsComposable
import com.orange.ods.compose.component.textfield.OdsExposedDropdownMenuTrailing
import com.orange.ods.compose.component.textfield.OdsTextField
import com.orange.ods.compose.component.utilities.BasicPreviewParameterProvider
import com.orange.ods.compose.component.utilities.Preview
import com.orange.ods.compose.component.utilities.UiModePreviews
import com.orange.ods.compose.component.utilities.enabledStateDescription
import kotlinx.parcelize.Parcelize

/**
Expand All @@ -50,9 +55,14 @@ fun OdsExposedDropdownMenu(
enabled: Boolean = true
) {
var expanded by remember { mutableStateOf(false) }
val menuBoxStateDescription = enabledStateDescription(enabled = enabled)
val menuBoxAction = if (enabled) stringResource(id = com.orange.ods.R.string.dropdown_menu_action) else ""

ExposedDropdownMenuBox(
modifier = modifier,
modifier = modifier.clearAndSetSemantics {
contentDescription = "$label, ${selectedItem.value.label}, $menuBoxAction"
stateDescription = menuBoxStateDescription
},
expanded = expanded,
onExpandedChange = {
expanded = !expanded
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,13 @@ import com.orange.ods.R
*/
@Composable
internal fun selectionStateDescription(selected: Boolean) =
if (selected) stringResource(id = R.string.state_selected) else stringResource(id = R.string.state_not_selected)
if (selected) stringResource(id = R.string.state_selected) else stringResource(id = R.string.state_not_selected)

/**
* Returns the enabled/disabled state ready for vocalization according to the [enabled] provided value.
*
* @param enabled Set it to true if the element is enabled, false otherwise.
*/
@Composable
internal fun enabledStateDescription(enabled: Boolean) =
if (!enabled) stringResource(id = R.string.state_disabled) else ""
3 changes: 3 additions & 0 deletions lib/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
-->

<resources>
<string name="state_disabled">Disabled</string>
<string name="state_selected">Selected</string>
<string name="state_not_selected">Not selected</string>

<string name="dropdown_menu_action">Double click to change selection</string>

<string name="text_field_password_show">Show password</string>
<string name="text_field_password_hide">Hide password</string>

Expand Down

0 comments on commit bcde27d

Please sign in to comment.