Skip to content

Conversation

@johnjohndoe
Copy link
Contributor

  • Add missing Checkbox role which is only set if onClick is set.
  • Add state description to output the checked state via TalkBack.

Relates #453, #417, #318

onCheckedChange = null,
modifier = modifier.semantics {
role = Checkbox
stateDescription = if (checked) "Checked" else "Unchecked"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where do you want strings to be maintained in the project?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we can depend on the string from the material component, or mimic that one, as I would hope that they handle it properly already

Copy link
Contributor Author

@johnjohndoe johnjohndoe Sep 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree. Ultimately it would be patched there to not depend on the handler being set.

@keta1
Copy link
Contributor

keta1 commented Sep 26, 2025

https://github.com/androidx/androidx/blob/b55ab743eb05c12eac83aa9c77900bd2c4eb773f/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Checkbox.kt#L141

@Composable
fun Checkbox(
    checked: Boolean,
    onCheckedChange: ((Boolean) -> Unit)?,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    interactionSource: MutableInteractionSource? = null,
    colors: CheckboxColors = CheckboxDefaults.colors(),
) {
    TriStateCheckbox(
        state = ToggleableState(checked),
        onClick =
            if (onCheckedChange != null) {
                { onCheckedChange(!checked) }
            } else null,
        interactionSource = interactionSource,
        enabled = enabled,
        colors = colors,
        modifier = modifier,
    )
}
val toggleableModifier =
        if (onClick != null) {
            Modifier.triStateToggleable(
                state = state,
                onClick = onClick,
                enabled = enabled,
                role = Role.Checkbox,
                interactionSource = interactionSource,
                indication = ripple(bounded = false, radius = CheckboxRippleRadius),
            )
        } else {
            Modifier
        }

it may only be necessary to pass an empty lambda to onCheckedChange

@johnjohndoe
Copy link
Contributor Author

Thanks, I will try that out.

@johnjohndoe
Copy link
Contributor Author

Yes, once I set onCheckedChange = { _ -> }, then TalkBack will read out the checked state. It does break the layout though:

samplecheckbox

Also, once I set semantics(mergeDescendants = true) {} on the Row in MarkdownListItem then the checkbox state is not longer output.

@johnjohndoe
Copy link
Contributor Author

⏸️ I won't be able to work on this within this month.

+ Add missing Checkbox role which is only set if onClick is set.
+ Add state description to output the checked state via TalkBack.

Relates mikepenz#453, mikepenz#417, mikepenz#318
@johnjohndoe
Copy link
Contributor Author

I rebased the branch and check the rendering and TalkBack output again. Now it looks fine - to layout issue anymore. Hence, ready for review.

@johnjohndoe johnjohndoe marked this pull request as ready for review November 8, 2025 23:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants