While working with JUCE’s accessibility handler and getCurrentState, I encountered an issue where juce::AccessibleState does not behave as expected when trying to mark a custom component as selectable. Specifically, using withSelectable and withSelected does not update the component’s state correctly when using the radioButton role. Instead, the workaround is to use withCheckable and withChecked, to get the desired “selected” state.
The expected approach for making a radio button accessible is:
// using juce::AccessibilityRole::radioButton
juce::AccessibleState MyAccessibilityHandler::getCurrentState() const
{
auto state = juce::AccessibilityHandler::getCurrentState();
if (customComponent.getSelectableState())
{
state = state.withSelectable();
if (customComponent.getSelectedState())
state = state.withSelected();
}
return state;
}
The workaround
juce::AccessibleState MyAccessibilityHandler::getCurrentState() const
{
auto state = juce::AccessibilityHandler::getCurrentState();
if (customComponent.getSelectableState())
{
state = state.withCheckable();
if (customComponent.getSelectedState())
state = state.withChecked();
}
return state;
}
This was observed while testing on macOS 15.3 using JUCE 8.0.4.
