Skip to content

Commit b8c7efc

Browse files
Fixed [Windows] MAUI Entry in Windows always shows ClearButton despite ClearButtonVisibility set to 'Never' (dotnet#25567)
* Fixed-Entry-ClearButtonVisibility-Issue * Added-Windows-SnapShot * Added-SnapShots * Added-Additional-TestCases * Added-new-testcases. * Modified-Entry-Cases * Updated tests. * Added-SnapShots * Fixed-Entry-ClearButtonVisibility-Issue * Added-Windows-SnapShot * Added-SnapShots * Added-Additional-TestCases * Added-new-testcases. * Modified-Entry-Cases * Updated tests. * Added-SnapShots * Added-TestCase-Windows-Only --------- Co-authored-by: Prakash Kannan <prakash.kannan@syncfusion.com> Co-authored-by: prakashKannanSf3972 <127308739+prakashKannanSf3972@users.noreply.github.com>
1 parent 3c4c27c commit b8c7efc

File tree

6 files changed

+96
-0
lines changed

6 files changed

+96
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:local="clr-namespace:Maui.Controls.Sample.Issues"
5+
x:Class="Maui.Controls.Sample.Issues.Issue25473">
6+
7+
<VerticalStackLayout Spacing="20" HorizontalOptions="Center">
8+
<!-- Entry control with ClearButtonVisibility set to 'WhileEditing' -->
9+
<HorizontalStackLayout>
10+
<Entry
11+
x:Name="mainEntryField"
12+
AutomationId="MainEntryField"
13+
BackgroundColor="Transparent"
14+
ClearButtonVisibility="WhileEditing"
15+
FontSize="16"
16+
ReturnType="Search"
17+
IsSpellCheckEnabled="false"
18+
IsTextPredictionEnabled="false"
19+
HorizontalOptions="Fill"
20+
VerticalOptions="Center"
21+
MinimumWidthRequest="300"
22+
VerticalTextAlignment="Center"/>
23+
</HorizontalStackLayout>
24+
25+
<!-- Button to toggle the ClearButton visibility for the Entry control -->
26+
<Button AutomationId="ToggleClearButtonVisibilityButton"
27+
Text="Toggle Clear Button Visibility"
28+
Clicked="OnToggleClearButtonVisibilityClicked"/>
29+
</VerticalStackLayout>
30+
</ContentPage>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace Maui.Controls.Sample.Issues
2+
{
3+
4+
[Issue(IssueTracker.Github, 25473, "MAUI Entry in Windows always shows ClearButton despite ClearButtonVisibility set to 'Never'", PlatformAffected.UWP)]
5+
public partial class Issue25473 : ContentPage
6+
{
7+
public Issue25473()
8+
{
9+
InitializeComponent();
10+
}
11+
12+
private void OnToggleClearButtonVisibilityClicked(object sender, EventArgs e)
13+
{
14+
if(mainEntryField.ClearButtonVisibility == ClearButtonVisibility.Never)
15+
mainEntryField.ClearButtonVisibility = ClearButtonVisibility.WhileEditing;
16+
else
17+
mainEntryField.ClearButtonVisibility = ClearButtonVisibility.Never;
18+
}
19+
}
20+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#if WINDOWS
2+
using Microsoft.Maui.Platform;
3+
using NUnit.Framework;
4+
using UITest.Appium;
5+
using UITest.Core;
6+
7+
namespace Microsoft.Maui.TestCases.Tests.Issues
8+
{
9+
public class Issue25473 : _IssuesUITest
10+
{
11+
public Issue25473(TestDevice testDevice) : base(testDevice)
12+
{
13+
}
14+
15+
public override string Issue => "MAUI Entry in Windows always shows ClearButton despite ClearButtonVisibility set to 'Never'";
16+
17+
[Test]
18+
[Category(UITestCategories.Entry)]
19+
public void VerifyEntryClearButtonVisibilitySetToWhileEditing()
20+
{
21+
App.WaitForElement("ToggleClearButtonVisibilityButton");
22+
App.Click("ToggleClearButtonVisibilityButton");
23+
App.ClearText("MainEntryField");
24+
App.EnterText("MainEntryField", "ClearButton is set to WhileEditing");
25+
App.Tap("MainEntryField");
26+
VerifyScreenshot();
27+
}
28+
29+
[Test]
30+
[Category(UITestCategories.Entry)]
31+
public void VerifyEntryClearButtonVisibilitySetToNever()
32+
{
33+
App.WaitForElement("ToggleClearButtonVisibilityButton");
34+
App.Click("ToggleClearButtonVisibilityButton");
35+
App.ClearText("MainEntryField");
36+
App.EnterText("MainEntryField", "ClearButton is set to Never");
37+
App.Tap("MainEntryField");
38+
VerifyScreenshot();
39+
}
40+
}
41+
}
42+
#endif
8.45 KB
Loading
8.93 KB
Loading

src/Core/src/Platform/Windows/MauiTextBox.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,20 @@ static void OnIsDeleteButtonEnabledPropertyChanged(DependencyObject d, Dependenc
6868
Button? deleteButton = element.GetDescendantByName<Button>(DeleteButtonElementName);
6969

7070
// Adjust the second column's width to 'Auto' when the delete button is enabled, and set it to zero when disabled.
71+
// Disables the delete button when ClearButtonVisibility is set to Never, and enables it otherwise.
72+
// In WinUI, they set the opacity to '0' when the button is disabled. Here, we use IsEnabled to manage visibility.
7173
if (deleteButton?.Parent is Grid rootGrid && rootGrid.ColumnDefinitions.Count > 1)
7274
{
7375
int deleteButtonColumnIndex = Grid.GetColumn(deleteButton);
7476
if (GetIsDeleteButtonEnabled(element))
7577
{
7678
rootGrid.ColumnDefinitions[deleteButtonColumnIndex].Width = new UI.Xaml.GridLength(1, UI.Xaml.GridUnitType.Auto);
79+
deleteButton.IsEnabled = true;
7780
}
7881
else
7982
{
8083
rootGrid.ColumnDefinitions[deleteButtonColumnIndex].Width = new UI.Xaml.GridLength(0);
84+
deleteButton.IsEnabled = false;
8185
}
8286
}
8387
}

0 commit comments

Comments
 (0)