Skip to content

[Android] TouchBehavior prevents keyboard Tab navigation to next element - fix #2673

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

Merged
merged 2 commits into from
May 26, 2025

Conversation

kubaflo
Copy link
Contributor

@kubaflo kubaflo commented May 26, 2025

Description of Change

e.Handled = false; is essential here because it preserves native focus navigation. Without it, your behavior unintentionally blocks keyboard input from reaching other controls or triggering system logic.

This subtle line prevents your TouchBehavior from hijacking the keyboard navigation experience — especially important on Android where keyboard interactions are more commonly used with physical keyboards or accessibility tools.

Linked Issues

PR Checklist

  • Has a linked Issue, and the Issue has been approved(bug) or Championed (feature/proposal)
  • Has tests (if omitted, state reason in description)
  • Has samples (if omitted, state reason in description)
  • Rebased on top of main at time of PR
  • Changes adhere to coding standard
  • Documentation created or updated: https://github.com/MicrosoftDocs/CommunityToolkit/pulls
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
   x:Class="CommunityToolkit.Maui.Sample.Pages.WelcomePage"
   xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
   xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
   xmlns:mct="http://schemas.microsoft.com/dotnet/2022/maui/toolkit">
   <VerticalStackLayout>
   	<Label
   		Text="Hello, World!">
   		<Label.Behaviors>
   			<mct:TouchBehavior PressedOpacity="0.5"  PressedScale="0.5"/>
   		</Label.Behaviors>
   	</Label>

   	<Entry Placeholder="Entry"/>
   	<Entry Placeholder="Entry"/>
   	<Entry Placeholder="Entry"/>
   	<Entry Placeholder="Entry"/>
   </VerticalStackLayout>
</ContentPage>
Before After
Screen.Recording.2025-05-26.at.20.00.21.mov
Screen.Recording.2025-05-26.at.19.58.19.mov

@Copilot Copilot AI review requested due to automatic review settings May 26, 2025 17:54
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 updates the Android touch behavior to preserve native keyboard focus navigation by explicitly not marking key events as handled.

  • Added e.Handled = false; in OnKeyPressed to prevent hijacking keyboard input.
  • Ensures other controls and system logic continue receiving key events on Android.
Comments suppressed due to low confidence (1)

src/CommunityToolkit.Maui/Behaviors/PlatformBehaviors/Touch/TouchBehavior.android.cs:130

  • Add a unit or integration test to verify that OnKeyPressed leaves e.Handled as false and that keyboard navigation remains functional after this change.
e.Handled = false;

@kubaflo kubaflo changed the title Update TouchBehavior.android.cs [Android] TouchBehavior prevents keyboard Tab navigation to next element - fix May 26, 2025
Copy link
Member

@pictos pictos left a comment

Choose a reason for hiding this comment

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

Lgtm

Copy link
Collaborator

@TheCodeTraveler TheCodeTraveler left a comment

Choose a reason for hiding this comment

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

Thanks @kubaflo!! Approved ✅

I will resolve the errors in our build pipeline shortly then merge this PR 👍

@TheCodeTraveler TheCodeTraveler enabled auto-merge (squash) May 26, 2025 22:25
@kubaflo
Copy link
Contributor Author

kubaflo commented May 26, 2025

Thanks, @pictos and @TheCodeTraveler, for your prompt response! I need this fix for my app, so I greatly appreciate it!

@TheCodeTraveler
Copy link
Collaborator

No problem! This'll be in Friday's release.

@TheCodeTraveler TheCodeTraveler merged commit 723c8f9 into CommunityToolkit:main May 26, 2025
8 of 10 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators May 28, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] [Android] TouchBehavior prevents keyboard Tab navigation to next element
3 participants