Does anyone know how to tie together a Switch with...
# compose
Does anyone know how to tie together a Switch with a Text so that the switch announces the text as it’s focused. Best i can find is using the “contentDescription” semantic property on the switch, and that should announce it, but then the text will also get announced as it’s own thing.
👍 1
I’d put a
on the parent like so:
Copy code
  modifier = Modifier.toggleable(
      value = checked,
      onValueChange = { checked = !checked},
      role = Role.Switch
) {
      checked = checked,

      // null prevents the switch from being independently clickable
      onCheckedChange = null 
  Text( ... )
will do a
Modifier.semantics(mergeDescendants = true)
internally, which is the merging behavior that you want. Using
instead of
directly ensures that the entire merged content gets the correct semantics for a switch element in addition to just merging them. This also has the side effect (desired, IMO) of making the text clickable to toggle the switch as well.
☝️ 2
👌 1
Then I'd pass indication = null, save one
(or something?) and pass into both Checkbox and Text(with indication = null.) It would only show indication for Checkbox, but also allows clicking through text. Just like (but I forgot semantic ones so merge with the answer above)
👌 1