Skip to content

[iOS, Mac, Windows] Fixed CharacterSpacing for SearchBar text and placeholder text #30407

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

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

Conversation

Dhivya-SF4094
Copy link
Contributor

@Dhivya-SF4094 Dhivya-SF4094 commented Jul 3, 2025

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!

Issue Detail

The CharacterSpacing property in SearchBar behaves inconsistently across platforms:

  1. iOS/macOS: Not applied to search text or placeholder—both use default spacing.
  2. Windows: Applied to search text, but placeholder still shows default spacing.

Root Cause

iOS: The CharacterSpacing logic for SearchBar is defined in UpdateCharacterSpacing() in TextFieldExtensions.cs, shared across Entry, Editor, and SearchBar.

For Entry and Editor, it's triggered via MapFormatting(), which is called from MapText() (e.g., in Entry.iOS), ensuring spacing is applied on load and text change.
For SearchBar, MapFormatting() was not invoked, so CharacterSpacing was never applied to either the search text or placeholder.

Windows - The CharacterSpacing property of the SearchBar is applied only to the search text via the AutoSuggestBox.CharacterSpacing property. However, the placeholder text is rendered by a separate internal TextBlock that does not inherit this spacing, resulting in default character spacing for the placeholder.

Description of Change

iOS: The fix involves explicitly calling MapFormatting() within the MapText() method of SearchBar.iOS.

Windows: The fix explicitly locates the TextBlock rendering the placeholder using GetFirstDescendant() and applies the same CharacterSpacing to it within the OnLoaded lifecycle of the AutoSuggestBox. This ensures that both search text and placeholder text reflect the correct spacing consistently.

Validated the behaviour in the following platforms

  • Android
  • Windows
  • iOS
  • Mac

Issues Fixed:

Fixes #30366

Screenshots

Before  After 
PlaceHolder Text      
SearchBar Text      

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

Hey there @@Dhivya-SF4094! 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 Jul 3, 2025
@jsuarezruiz jsuarezruiz added the area-controls-searchbar SearchBar control label Jul 3, 2025
@Dhivya-SF4094 Dhivya-SF4094 changed the title [iOS, Mac, Windows] Fixed Character spacing for SearchBar Placeholder text [iOS, Mac, Windows] Fixed CharacterSpacing for SearchBar text and placeholder text Jul 3, 2025
@jsuarezruiz
Copy link
Contributor

/azp run MAUI-UITests-public

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Contributor

@jsuarezruiz jsuarezruiz left a comment

Choose a reason for hiding this comment

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

The added snapshots contains the cursor. Because is blinking, the test could randomly fail. Could you update the test to remove the cursor?
Use:

public static readonly BindableProperty IsCursorVisibleProperty =

@Dhivya-SF4094
Copy link
Contributor Author

The added snapshots contains the cursor. Because is blinking, the test could randomly fail. Could you update the test to remove the cursor? Use:

public static readonly BindableProperty IsCursorVisibleProperty =

@jsuarezruiz Updated the test sample to set IsCursorVisible to false using the UITestSearchBar.IsCursorVisibleProperty

@Dhivya-SF4094 Dhivya-SF4094 marked this pull request as ready for review July 4, 2025 10:49
@Dhivya-SF4094 Dhivya-SF4094 requested a review from a team as a code owner July 4, 2025 10:49
@jsuarezruiz
Copy link
Contributor

/azp run MAUI-UITests-public

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

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.

[iOS, Mac, Windows] SearchBar CharacterSpacing property is not working as expected
2 participants