Skip to content

[Android] Keyboard navigation does not work with RadioButtons with redefined appearance #30041

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kubaflo
Copy link
Contributor

@kubaflo kubaflo commented Jun 17, 2025

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Description of Change

This PR fixes a bug where RadioButton controls using a ControlTemplate do not support keyboard navigation (using arrow keys or Tab), breaking the expected accessibility behavior.

When a ControlTemplate is applied, the internal focusable or input-handling elements may be bypassed or not properly initialized for keyboard interaction. This change ensures that:

  • The RadioButton remains fully keyboard-navigable regardless of whether a ControlTemplate is used.
  • Navigation using arrow keys correctly moves focus between RadioButton instances in the same GroupName.
  • The control participates in the tab order appropriately, improving accessibility compliance.

Issues Fixed

Fixes #30040

Before After
Screen.Recording.2025-06-18.at.01.04.47.mov
Screen.Recording.2025-06-18.at.01.07.13.mov

@Copilot Copilot AI review requested due to automatic review settings June 17, 2025 23:18
@kubaflo kubaflo requested a review from a team as a code owner June 17, 2025 23:18
@kubaflo kubaflo self-assigned this Jun 17, 2025
@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Jun 17, 2025
@kubaflo kubaflo added version/android-13 and removed community ✨ Community Contribution labels Jun 17, 2025
Copy link
Contributor

Hey there @@kubaflo! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Jun 17, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes the bug where RadioButton controls with a redefined ControlTemplate were not fully keyboard-navigable on Android. Key changes include:

  • Adding a property to store the ContentViewGroup and subscribing to its KeyPress event.
  • Removing existing content views and re-adding the presented content.
  • Implementing a key press handler to toggle the radio button state on Enter/Space key presses.
Comments suppressed due to low confidence (1)

src/Controls/src/Core/RadioButton/RadioButton.Android.cs:7

  • [nitpick] Consider renaming the property 'contentViewGroup' to 'ContentViewGroup' to follow .NET PascalCase naming conventions for properties.
		ContentViewGroup? contentViewGroup { get; set; }

if (e?.Event is not null && e.Event.Action == Android.Views.KeyEventActions.Down &&
(e.Event.KeyCode == Android.Views.Keycode.Enter || e.Event.KeyCode == Android.Views.Keycode.Space))
{
IsChecked = !IsChecked;
Copy link
Preview

Copilot AI Jun 17, 2025

Choose a reason for hiding this comment

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

After toggling 'IsChecked' on key press, consider setting 'e.Handled = true' within this block to prevent further propagation of the key event.

Suggested change
IsChecked = !IsChecked;
IsChecked = !IsChecked;
e.Handled = true;

Copilot uses AI. Check for mistakes.

@kubaflo kubaflo added area-controls-radiobutton RadioButton, RadioButtonGroup t/a11y Relates to accessibility platform/android and removed version/android-13 labels Jun 17, 2025
Copy link
Contributor

@jsuarezruiz jsuarezruiz left a comment

Choose a reason for hiding this comment

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

Could you add a test case for this? For Android, can use the App.SendKeys method to send Tab key.

@kubaflo
Copy link
Contributor Author

kubaflo commented Jun 18, 2025

I will add a test once we decide if this PR makes sense or we should take a different approach

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-radiobutton RadioButton, RadioButtonGroup community ✨ Community Contribution platform/android t/a11y Relates to accessibility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Android] Keyboard navigation does not work with RadioButtons with redefined appearance
2 participants