Skip to content

Commit

Permalink
Fix for Windows SearchBar MaxLength > 0 not working properly. (#24919)
Browse files Browse the repository at this point in the history
* Fix Windows SearchBar MaxLength property

* Fix issue

* fix-5669-Fix for Windows SearchBar MaxLength > 0 not working properly.

* fix-5669-Taking child for AutoSuggestBox code has been moved to SearchBarExtension.cs.

* fix-5669-Removed unwanted parameter UpdateMaxLength().

* fix-5669-Changes committed for PublicAPI file.

* fix-5669-Getting Child of TextBox using GetChildren() method instead of using FindChildOfType.

* fix-5669-Optimized the code in the UpdateMaxLength() method.

* fix-5669-Removed Child count check for AutoSuggestBox Control.

* fix-5669-Updated the proper naming for the variable.

* Fix-5669-Removed unwanted space.

* fix-5669-Added missing namespace.

* fix-5669-Fix for Windows SearchBar MaxLength > 0 not working properly.

* fix-5669-Taking child for AutoSuggestBox code has been moved to SearchBarExtension.cs.

* fix-5669-Removed unwanted parameter UpdateMaxLength().

* fix-5669-Changes committed for PublicAPI file.

* fix-5669-Getting Child of TextBox using GetChildren() method instead of using FindChildOfType.

* fix-5669-Optimized the code in the UpdateMaxLength() method.

* fix-5669-Removed Child count check for AutoSuggestBox Control.

* fix-5669-Updated the proper naming for the variable.

* Fix-5669-Removed unwanted space.

* fix-5669-Added missing namespace.

* fix-5669-Added testcase images.

* fix-5669-Updated testcase images.

* fix-5669-Removed the Linq related codes.

* fix-5669-Unwanted code removed.

* fix-5669-Updated iOS testcase image.

---------

Co-authored-by: Javier Suárez Ruiz <javiersuarezruiz@hotmail.com>
  • Loading branch information
BagavathiPerumal and jsuarezruiz authored Oct 8, 2024
1 parent ddb222c commit 7f56f6c
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 0 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue5669.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?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.Issue5669">
<ContentPage.Content>
<StackLayout>
<SearchBar x:Name="searchbar" Text="Searchbar Control" MaxLength="3" AutomationId="SearchBar"/>
<HorizontalStackLayout>
<Label Text="MaxLength value is: "/>
<Label Text="{Binding Source={x:Reference searchbar}, Path=MaxLength}"/>
</HorizontalStackLayout>
<Button AutomationId="ChangeValue" Text="Change Value" x:Name="button" Clicked="Button_Clicked"/>
</StackLayout>
</ContentPage.Content>
</ContentPage>
17 changes: 17 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue5669.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Maui.Controls.Sample.Issues
{
[XamlCompilation(XamlCompilationOptions.Compile)]
[Issue(IssueTracker.Github, 5669, "Windows SearchBar MaxLength > 0 not working properly", PlatformAffected.UWP)]
public partial class Issue5669 : ContentPage
{
public Issue5669()
{
InitializeComponent();
}

private void Button_Clicked(object sender, EventArgs e)
{
searchbar.MaxLength = 4;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#if !MACCATALYST
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class Issue5669: _IssuesUITest
{
public override string Issue => "Windows SearchBar MaxLength > 0 not working properly";
public Issue5669(TestDevice testDevice) : base(testDevice)
{
}

[Test]
[Category(UITestCategories.SearchBar)]
public void SearchBarMaxLength()
{
App.WaitForElement("SearchBar");
App.EnterText("SearchBar", "r");
App.Click("ChangeValue");
App.EnterText("SearchBar", "r");
App.EnterText("SearchBar", "c");
VerifyScreenshot();
}
}
}
#endif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions src/Core/src/Platform/Windows/SearchBarExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,19 @@ public static void UpdateMaxLength(this AutoSuggestBox platformControl, ISearchB
if (maxLength == -1)
maxLength = int.MaxValue;

var children = platformControl.GetChildren<TextBox>();
if (children is not null)
{
foreach (var textBox in children)
{
if (textBox is not null)
{
textBox.MaxLength = searchBar.MaxLength;
break;
}
}
}

if (maxLength == 0)
MauiAutoSuggestBox.SetIsReadOnly(platformControl, true);
else
Expand Down

0 comments on commit 7f56f6c

Please sign in to comment.