Skip to content
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

[Windows] Fixed the issue with SearchBar focus and unfocus events. #28529

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Ahamed-Ali
Copy link
Contributor

Root Cause of the issue

  • In ViewHandler.Windows, FocusManager.GotFocus and LostFocus are handled for other controls. However, for AutoSuggestBox, when handling the GotFocus or LostFocus methods, tapping the AutoSuggestBox causes e.NewFocusedElement and e.OldFocusedElement to be a TextBox (which is the ControlTemplate of AutoSuggestBox and receives the focus). As a result, when comparing the PlatformView with the appropriate handler in FocusManagerMapping, the condition is not satisfied, causing the focus and unfocus events to not work correctly.

Description of Change

  • To address this, I have specifically handled the focus and unfocus events for AutoSuggestBox in SearchBarHandler.Windows.

Regressed PR

Issues Fixed

Fixes #28419

Tested the behaviour in the following platforms

  • Android
  • Windows
  • iOS
  • Mac

Screenshot

Before Issue Fix After Issue Fix
SearchBarIssueVideo.mp4
SearchBarFixVideo.mp4

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

Hey there @Ahamed-Ali! 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 partner/syncfusion Issues / PR's with Syncfusion collaboration label Mar 20, 2025
Copy link
Member

@mattleibow mattleibow left a comment

Choose a reason for hiding this comment

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

I know you are not done yet, but we do lose the logic in the UpdateIsFocused method in the manager. Maybe that method should be private protected and we use that?

@mattleibow mattleibow added the area-controls-searchbar SearchBar control label Mar 20, 2025
@Ahamed-Ali
Copy link
Contributor Author

I know you are not done yet, but we do lose the logic in the UpdateIsFocused method in the manager. Maybe that method should be private protected and we use that?

Yes, I have now utilized UpdateIsFocused method from ViewHandler.Windows to preserve the existing logic. Please let me know if you have any other concerns. @mattleibow

@Ahamed-Ali Ahamed-Ali marked this pull request as ready for review March 21, 2025 10:37
@Ahamed-Ali Ahamed-Ali requested a review from a team as a code owner March 21, 2025 10:37
@jsuarezruiz
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

// However, for AutoSuggestBox, when handling the GotFocus or LostFocus methods, tapping the AutoSuggestBox causes e.NewFocusedElement and e.OldFocusedElement to be a TextBox (which receives the focus).
// As a result, when comparing the PlatformView with the appropriate handler in FocusManagerMapping, the condition is not satisfied, causing the focus and unfocus methods to not work correctly.
// To address this, I have specifically handled the focus and unfocus events for AutoSuggestBox here.
platformView.GotFocus += OnGotFocus;
Copy link
Contributor

Choose a reason for hiding this comment

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

Good comment!

I was wondering if we could improve the logic in ViewHandler.Windows to manage the focus, and if comparing also based on derived types would make sense, even though AutoSuggestBox doesn't derive from Textbox (it does from ItemsControl). So, I think changes are fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-searchbar SearchBar control community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SearchBar focus/unfocus do not fire on Windows
3 participants