-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Issue-Resolver] Add ShowsCancelButton property to SearchBar and SearchHandler #33010
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -117,6 +117,10 @@ void SearchHandlerPropertyChanged(object sender, System.ComponentModel.PropertyC | |
| { | ||
| UpdateSearchBarVerticalTextAlignment(_uiSearchBar.FindDescendantView<UITextField>()); | ||
| } | ||
| else if (e.Is(SearchHandler.ShowsCancelButtonProperty)) | ||
| { | ||
| UpdateShowsCancelButton(); | ||
| } | ||
| } | ||
|
|
||
| void GetDefaultSearchBarColors(UISearchBar searchBar) | ||
|
|
@@ -319,13 +323,29 @@ void UpdateKeyboard() | |
| _uiSearchBar.ReloadInputViews(); | ||
| } | ||
|
|
||
| void UpdateShowsCancelButton() | ||
| { | ||
| if (_searchHandler.IsFocused) | ||
| { | ||
| _uiSearchBar.SetShowsCancelButton(_searchHandler.ShowsCancelButton, true); | ||
| } | ||
| } | ||
|
|
||
| void OnEditingEnded(object sender, EventArgs e) | ||
| { | ||
| if (_searchHandler.ShowsCancelButton) | ||
| { | ||
| _uiSearchBar.SetShowsCancelButton(false, true); | ||
| } | ||
| _searchHandler.SetIsFocused(false); | ||
| } | ||
|
|
||
| void OnEditingStarted(object sender, EventArgs e) | ||
| { | ||
| if (_searchHandler.ShowsCancelButton) | ||
| { | ||
| _uiSearchBar.SetShowsCancelButton(true, true); | ||
| } | ||
|
Comment on lines
+345
to
+348
|
||
| UpdateCancelButtonColor(_uiSearchBar.FindDescendantView<UIButton>()); | ||
| _searchHandler.SetIsFocused(true); | ||
| //ElementController?.SetValueFromRenderer(VisualElement.IsFocusedPropertyKey, true); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,7 @@ | ||
| #nullable enable | ||
| Microsoft.Maui.Controls.SearchBar.ShowsCancelButton.get -> bool | ||
| Microsoft.Maui.Controls.SearchBar.ShowsCancelButton.set -> void | ||
| ~static readonly Microsoft.Maui.Controls.SearchBar.ShowsCancelButtonProperty -> Microsoft.Maui.Controls.BindableProperty | ||
| Microsoft.Maui.Controls.SearchHandler.ShowsCancelButton.get -> bool | ||
| Microsoft.Maui.Controls.SearchHandler.ShowsCancelButton.set -> void | ||
| ~static readonly Microsoft.Maui.Controls.SearchHandler.ShowsCancelButtonProperty -> Microsoft.Maui.Controls.BindableProperty |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,8 @@ | ||
| #nullable enable | ||
| ~override Microsoft.Maui.Controls.Platform.Compatibility.ShellFlyoutRenderer.ViewWillTransitionToSize(CoreGraphics.CGSize toSize, UIKit.IUIViewControllerTransitionCoordinator coordinator) -> void | ||
| Microsoft.Maui.Controls.SearchBar.ShowsCancelButton.get -> bool | ||
| Microsoft.Maui.Controls.SearchBar.ShowsCancelButton.set -> void | ||
| ~static readonly Microsoft.Maui.Controls.SearchBar.ShowsCancelButtonProperty -> Microsoft.Maui.Controls.BindableProperty | ||
| Microsoft.Maui.Controls.SearchHandler.ShowsCancelButton.get -> bool | ||
| Microsoft.Maui.Controls.SearchHandler.ShowsCancelButton.set -> void | ||
| ~static readonly Microsoft.Maui.Controls.SearchHandler.ShowsCancelButtonProperty -> Microsoft.Maui.Controls.BindableProperty |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,8 @@ | ||
| #nullable enable | ||
| ~override Microsoft.Maui.Controls.Platform.Compatibility.ShellFlyoutRenderer.ViewWillTransitionToSize(CoreGraphics.CGSize toSize, UIKit.IUIViewControllerTransitionCoordinator coordinator) -> void | ||
| Microsoft.Maui.Controls.SearchBar.ShowsCancelButton.get -> bool | ||
| Microsoft.Maui.Controls.SearchBar.ShowsCancelButton.set -> void | ||
| ~static readonly Microsoft.Maui.Controls.SearchBar.ShowsCancelButtonProperty -> Microsoft.Maui.Controls.BindableProperty | ||
| Microsoft.Maui.Controls.SearchHandler.ShowsCancelButton.get -> bool | ||
| Microsoft.Maui.Controls.SearchHandler.ShowsCancelButton.set -> void | ||
| ~static readonly Microsoft.Maui.Controls.SearchHandler.ShowsCancelButtonProperty -> Microsoft.Maui.Controls.BindableProperty |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,7 @@ | ||
| #nullable enable | ||
| Microsoft.Maui.Controls.SearchBar.ShowsCancelButton.get -> bool | ||
| Microsoft.Maui.Controls.SearchBar.ShowsCancelButton.set -> void | ||
| ~static readonly Microsoft.Maui.Controls.SearchBar.ShowsCancelButtonProperty -> Microsoft.Maui.Controls.BindableProperty | ||
| Microsoft.Maui.Controls.SearchHandler.ShowsCancelButton.get -> bool | ||
| Microsoft.Maui.Controls.SearchHandler.ShowsCancelButton.set -> void | ||
| ~static readonly Microsoft.Maui.Controls.SearchHandler.ShowsCancelButtonProperty -> Microsoft.Maui.Controls.BindableProperty |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,7 @@ | ||
| #nullable enable | ||
| Microsoft.Maui.Controls.SearchBar.ShowsCancelButton.get -> bool | ||
| Microsoft.Maui.Controls.SearchBar.ShowsCancelButton.set -> void | ||
| ~static readonly Microsoft.Maui.Controls.SearchBar.ShowsCancelButtonProperty -> Microsoft.Maui.Controls.BindableProperty | ||
| Microsoft.Maui.Controls.SearchHandler.ShowsCancelButton.get -> bool | ||
| Microsoft.Maui.Controls.SearchHandler.ShowsCancelButton.set -> void | ||
| ~static readonly Microsoft.Maui.Controls.SearchHandler.ShowsCancelButtonProperty -> Microsoft.Maui.Controls.BindableProperty |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,7 @@ | ||
| #nullable enable | ||
| Microsoft.Maui.Controls.SearchBar.ShowsCancelButton.get -> bool | ||
| Microsoft.Maui.Controls.SearchBar.ShowsCancelButton.set -> void | ||
| ~static readonly Microsoft.Maui.Controls.SearchBar.ShowsCancelButtonProperty -> Microsoft.Maui.Controls.BindableProperty | ||
| Microsoft.Maui.Controls.SearchHandler.ShowsCancelButton.get -> bool | ||
| Microsoft.Maui.Controls.SearchHandler.ShowsCancelButton.set -> void | ||
| ~static readonly Microsoft.Maui.Controls.SearchHandler.ShowsCancelButtonProperty -> Microsoft.Maui.Controls.BindableProperty |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,7 @@ | ||
| #nullable enable | ||
| Microsoft.Maui.Controls.SearchBar.ShowsCancelButton.get -> bool | ||
| Microsoft.Maui.Controls.SearchBar.ShowsCancelButton.set -> void | ||
| ~static readonly Microsoft.Maui.Controls.SearchBar.ShowsCancelButtonProperty -> Microsoft.Maui.Controls.BindableProperty | ||
| Microsoft.Maui.Controls.SearchHandler.ShowsCancelButton.get -> bool | ||
| Microsoft.Maui.Controls.SearchHandler.ShowsCancelButton.set -> void | ||
| ~static readonly Microsoft.Maui.Controls.SearchHandler.ShowsCancelButtonProperty -> Microsoft.Maui.Controls.BindableProperty |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,9 @@ public partial class SearchBar : InputView, ITextAlignmentElement, ISearchBarCon | |
| /// <summary>Bindable property for <see cref="CancelButtonColor"/>.</summary> | ||
| public static readonly BindableProperty CancelButtonColorProperty = BindableProperty.Create(nameof(CancelButtonColor), typeof(Color), typeof(SearchBar), default(Color)); | ||
|
|
||
| /// <summary>Bindable property for <see cref="ShowsCancelButton"/>.</summary> | ||
| public static readonly BindableProperty ShowsCancelButtonProperty = BindableProperty.Create(nameof(ShowsCancelButton), typeof(bool), typeof(SearchBar), true); | ||
|
|
||
| /// <summary>Bindable property for <see cref="SearchIconColor"/>.</summary> | ||
| public static readonly BindableProperty SearchIconColorProperty = BindableProperty.Create(nameof(SearchIconColor), typeof(Color), typeof(SearchBar), default(Color)); | ||
|
|
||
|
|
@@ -94,6 +97,20 @@ public Color CancelButtonColor | |
| get { return (Color)GetValue(CancelButtonColorProperty); } | ||
| set { SetValue(CancelButtonColorProperty, value); } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets a value that indicates whether the cancel button is shown. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// On iOS, the cancel button appears when the search bar is focused and allows users to dismiss the keyboard. | ||
| /// Default value is <c>true</c>. | ||
| /// </remarks> | ||
| public bool ShowsCancelButton | ||
| { | ||
| get { return (bool)GetValue(ShowsCancelButtonProperty); } | ||
| set { SetValue(ShowsCancelButtonProperty, value); } | ||
| } | ||
|
Comment on lines
+101
to
+112
|
||
|
|
||
| /// <summary> | ||
| /// Gets or sets the color of the search icon in the <see cref="SearchBar"/>. | ||
| /// </summary> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -157,6 +157,9 @@ public Color TextColor | |
| /// <summary>Bindable property for <see cref="CancelButtonColor"/>.</summary> | ||
| public static readonly BindableProperty CancelButtonColorProperty = BindableProperty.Create(nameof(CancelButtonColor), typeof(Color), typeof(SearchHandler), default(Color)); | ||
|
|
||
| /// <summary>Bindable property for <see cref="ShowsCancelButton"/>.</summary> | ||
| public static readonly BindableProperty ShowsCancelButtonProperty = BindableProperty.Create(nameof(ShowsCancelButton), typeof(bool), typeof(SearchHandler), true); | ||
|
|
||
| /// <summary>Bindable property for <see cref="FontFamily"/>.</summary> | ||
| public static readonly BindableProperty FontFamilyProperty = FontElement.FontFamilyProperty; | ||
|
|
||
|
|
@@ -200,6 +203,19 @@ public Color CancelButtonColor | |
| set { SetValue(CancelButtonColorProperty, value); } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets a value that indicates whether the cancel button is shown. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// On iOS, the cancel button appears when the search bar is focused and allows users to dismiss the keyboard. | ||
| /// Default value is <c>true</c>. | ||
| /// </remarks> | ||
| public bool ShowsCancelButton | ||
| { | ||
| get { return (bool)GetValue(ShowsCancelButtonProperty); } | ||
| set { SetValue(ShowsCancelButtonProperty, value); } | ||
| } | ||
|
Comment on lines
+206
to
+217
|
||
|
|
||
|
|
||
| /// <include file="../../../docs/Microsoft.Maui.Controls/SearchHandler.xml" path="//Member[@MemberName='FontAttributes']/Docs/*" /> | ||
| public FontAttributes FontAttributes | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| <?xml version="1.0" encoding="utf-8" ?> | ||
| <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
| xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
| x:Class="Maui.Controls.Sample.Issues.Issue33008" | ||
| Title="Issue 33008 - ShowsCancelButton"> | ||
|
|
||
| <Shell.SearchHandler> | ||
| <SearchHandler Placeholder="Search..." | ||
| AutomationId="SearchHandler" | ||
| x:Name="SearchHandler" | ||
| ShowsCancelButton="True"/> | ||
| </Shell.SearchHandler> | ||
|
|
||
| <ScrollView> | ||
| <VerticalStackLayout Padding="20" | ||
| Spacing="15"> | ||
| <Label Text="ShowsCancelButton Property Tests" | ||
| FontSize="18" | ||
| FontAttributes="Bold" | ||
| AutomationId="TitleLabel"/> | ||
|
|
||
| <!-- SearchBar Tests --> | ||
| <Label Text="SearchBar Tests" | ||
| FontSize="16" | ||
| FontAttributes="Bold" | ||
| Margin="0,10,0,0"/> | ||
|
|
||
| <Label Text="1. Default (true):" | ||
| FontAttributes="Bold"/> | ||
| <SearchBar x:Name="SearchBarDefault" | ||
| Placeholder="Default - shows cancel when typing" | ||
| AutomationId="SearchBarDefault"/> | ||
|
|
||
| <Label Text="2. ShowsCancelButton=True:" | ||
| FontAttributes="Bold"/> | ||
| <SearchBar x:Name="SearchBarTrue" | ||
| Placeholder="True - shows cancel when typing" | ||
| ShowsCancelButton="True" | ||
| AutomationId="SearchBarTrue"/> | ||
|
|
||
| <Label Text="3. ShowsCancelButton=False:" | ||
| FontAttributes="Bold"/> | ||
| <SearchBar x:Name="SearchBarFalse" | ||
| Placeholder="False - NEVER shows cancel" | ||
| ShowsCancelButton="False" | ||
| AutomationId="SearchBarFalse"/> | ||
|
|
||
| <Button Text="Set Text" | ||
| Clicked="OnSetText" | ||
| AutomationId="SetTextButton"/> | ||
|
|
||
| <!-- Status --> | ||
| <BoxView HeightRequest="2" | ||
| Color="Gray" | ||
| Margin="0,10,0,0"/> | ||
| <Label Text="Status:" | ||
| FontAttributes="Bold"/> | ||
| <Label x:Name="StatusLabel" | ||
| Text="Ready" | ||
| AutomationId="StatusLabel"/> | ||
|
|
||
| </VerticalStackLayout> | ||
| </ScrollView> | ||
| </ContentPage> |
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,27 @@ | ||||||||||||||||
| namespace Maui.Controls.Sample.Issues; | ||||||||||||||||
|
|
||||||||||||||||
| [Issue(IssueTracker.Github, 33008, "SearchBar and SearchHandler ShowsCancelButton property", PlatformAffected.iOS)] | ||||||||||||||||
| public class Issue33008Shell : Shell | ||||||||||||||||
| { | ||||||||||||||||
| public Issue33008Shell() | ||||||||||||||||
| { | ||||||||||||||||
| Items.Add(new Issue33008()); | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
|
Comment on lines
+4
to
+10
|
||||||||||||||||
| public class Issue33008Shell : Shell | |
| { | |
| public Issue33008Shell() | |
| { | |
| Items.Add(new Issue33008()); | |
| } | |
| } |
Copilot
AI
Dec 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The OnSetText method sets SearchHandler.Query = "Test text" but there's no SearchHandler instance accessible in the ContentPage scope. The SearchHandler is defined in the XAML as Shell.SearchHandler, not as a field accessible via this.SearchHandler.
This code will result in a null reference exception at runtime. To fix this, either:
- Add
x:Name="SearchHandler"to the SearchHandler in XAML (already present) and access it via the name - Use
Shell.GetSearchHandler(this)to retrieve the SearchHandler - Store a reference to the SearchHandler in a field during InitializeComponent()
| SearchHandler.Query = "Test text"; | |
| } | |
| var searchHandler = Shell.GetSearchHandler(this); | |
| if (searchHandler != null) | |
| { | |
| searchHandler.Query = "Test text"; | |
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,29 @@ | ||||||
| using NUnit.Framework; | ||||||
| using UITest.Appium; | ||||||
| using UITest.Core; | ||||||
|
|
||||||
| namespace Microsoft.Maui.TestCases.Tests.Issues; | ||||||
|
|
||||||
| public class Issue33008 : _IssuesUITest | ||||||
| { | ||||||
| public override string Issue => "SearchBar and SearchHandler ShowsCancelButton property"; | ||||||
|
|
||||||
| public Issue33008(TestDevice device) : base(device) { } | ||||||
|
|
||||||
| [Test] | ||||||
| [Category(UITestCategories.SearchBar)] | ||||||
| public void SearchBarShowsCancelButtonWorks() | ||||||
| { | ||||||
| App.WaitForElement("TitleLabel"); | ||||||
| App.Tap("SetTextButton"); | ||||||
| App.EnterText("Search...", "Test text"); | ||||||
|
||||||
| App.EnterText("Search...", "Test text"); | |
| App.EnterText("SearchBarDefault", "Test text"); |
Copilot
AI
Dec 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR description claims "Device tests added (5 comprehensive tests, all passing)" but the actual test file only contains a single test method SearchBarShowsCancelButtonWorks(). The description mentions specific test methods like ShowsCancelButtonDefaultsToTrue, ShowsCancelButtonTrueShowsCancelButton, ShowsCancelButtonFalseHidesCancelButton, ShowsCancelButtonNoTextNeverShowsCancelButton, and ShowsCancelButtonCanBeToggledDynamically, but none of these tests exist in the code.
Additionally, the test doesn't actually verify that the cancel button behavior is working correctly - it only sets text and checks a status label. There's no assertion that validates the ShowsCancelButton property affects the native control's cancel button visibility.
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -12,6 +12,11 @@ public interface ISearchBar : IView, ITextInput, ITextAlignment | |||||||
| /// </summary> | ||||||||
| Color CancelButtonColor { get; } | ||||||||
|
|
||||||||
| /// <summary> | ||||||||
| /// Gets a value indicating whether the cancel button should be displayed. | ||||||||
|
||||||||
| /// Gets a value indicating whether the cancel button should be displayed. | |
| /// Gets a value indicating whether the cancel button should be displayed. | |
| /// On iOS, the cancel button appears when the search bar contains text. This property has no effect on Android, Windows, or Tizen platforms. |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -112,6 +112,11 @@ public static void MapCancelButtonColor(ISearchBarHandler handler, ISearchBar se | |||||||
| handler.PlatformView?.UpdateCancelButtonColor(searchBar); | ||||||||
| } | ||||||||
|
|
||||||||
| public static void MapShowsCancelButton(ISearchBarHandler handler, ISearchBar searchBar) | ||||||||
| { | ||||||||
| // ShowsCancelButton is iOS-specific behavior | ||||||||
|
||||||||
| // ShowsCancelButton is iOS-specific behavior | |
| // ShowsCancelButton is an iOS and MacCatalyst-specific behavior (UISearchBar). | |
| // Windows' AutoSuggestBox does not have an equivalent feature. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -117,10 +117,12 @@ public static void UpdateIsReadOnly(this UISearchBar uiSearchBar, ISearchBar sea | |
| } | ||
|
|
||
| internal static bool ShouldShowCancelButton(this ISearchBar searchBar) => | ||
| !string.IsNullOrEmpty(searchBar.Text); | ||
| searchBar.ShowsCancelButton && !string.IsNullOrEmpty(searchBar.Text); | ||
|
|
||
| public static void UpdateCancelButton(this UISearchBar uiSearchBar, ISearchBar searchBar) | ||
| { | ||
| // Respect the ShowsCancelButton property - if false, never show the button | ||
| // If true, show it based on whether there's text (iOS standard behavior) | ||
| uiSearchBar.ShowsCancelButton = searchBar.ShouldShowCancelButton(); | ||
|
Comment on lines
+120
to
126
|
||
|
|
||
| // We can't cache the cancel button reference because iOS drops it when it's not displayed | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,3 @@ | ||
| #nullable enable | ||
| Microsoft.Maui.ISearchBar.ShowsCancelButton.get -> bool | ||
| static Microsoft.Maui.Handlers.SearchBarHandler.MapShowsCancelButton(Microsoft.Maui.Handlers.ISearchBarHandler! handler, Microsoft.Maui.ISearchBar! searchBar) -> void |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,4 @@ | ||
| #nullable enable | ||
| override Microsoft.Maui.Platform.MauiView.DidUpdateFocus(UIKit.UIFocusUpdateContext! context, UIKit.UIFocusAnimationCoordinator! coordinator) -> void | ||
| Microsoft.Maui.ISearchBar.ShowsCancelButton.get -> bool | ||
| static Microsoft.Maui.Handlers.SearchBarHandler.MapShowsCancelButton(Microsoft.Maui.Handlers.ISearchBarHandler! handler, Microsoft.Maui.ISearchBar! searchBar) -> void |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,4 @@ | ||
| #nullable enable | ||
| override Microsoft.Maui.Platform.MauiView.DidUpdateFocus(UIKit.UIFocusUpdateContext! context, UIKit.UIFocusAnimationCoordinator! coordinator) -> void | ||
| Microsoft.Maui.ISearchBar.ShowsCancelButton.get -> bool | ||
| static Microsoft.Maui.Handlers.SearchBarHandler.MapShowsCancelButton(Microsoft.Maui.Handlers.ISearchBarHandler! handler, Microsoft.Maui.ISearchBar! searchBar) -> void |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,3 @@ | ||
| #nullable enable | ||
| Microsoft.Maui.ISearchBar.ShowsCancelButton.get -> bool | ||
| static Microsoft.Maui.Handlers.SearchBarHandler.MapShowsCancelButton(Microsoft.Maui.Handlers.ISearchBarHandler! handler, Microsoft.Maui.ISearchBar! searchBar) -> void |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,3 @@ | ||
| #nullable enable | ||
| Microsoft.Maui.ISearchBar.ShowsCancelButton.get -> bool | ||
| static Microsoft.Maui.Handlers.SearchBarHandler.MapShowsCancelButton(Microsoft.Maui.Handlers.ISearchBarHandler! handler, Microsoft.Maui.ISearchBar! searchBar) -> void |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,3 @@ | ||
| #nullable enable | ||
| Microsoft.Maui.ISearchBar.ShowsCancelButton.get -> bool | ||
| static Microsoft.Maui.Handlers.SearchBarHandler.MapShowsCancelButton(Microsoft.Maui.IViewHandler! handler, Microsoft.Maui.ISearchBar! searchBar) -> void |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,3 @@ | ||
| #nullable enable | ||
| Microsoft.Maui.ISearchBar.ShowsCancelButton.get -> bool | ||
| static Microsoft.Maui.Handlers.SearchBarHandler.MapShowsCancelButton(Microsoft.Maui.IViewHandler! handler, Microsoft.Maui.ISearchBar! searchBar) -> void |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,3 @@ | ||
| #nullable enable | ||
| Microsoft.Maui.ISearchBar.ShowsCancelButton.get -> bool | ||
| static Microsoft.Maui.Handlers.SearchBarHandler.MapShowsCancelButton(Microsoft.Maui.IViewHandler! handler, Microsoft.Maui.ISearchBar! searchBar) -> void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
UpdateShowsCancelButton()method only updates the cancel button visibility if the SearchHandler is currently focused. However, when the property changes while unfocused, the cancel button state won't be updated until the next focus change event.This could lead to unexpected behavior where changing
ShowsCancelButtonfromtruetofalsewhile unfocused won't take effect until the user focuses the search bar again. Consider updating the method to handle both focused and unfocused states, or at a minimum, document this behavior limitation.