diff --git a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_AutoSuggestBox.cs b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_AutoSuggestBox.cs index b65514392f24..446807e45143 100644 --- a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_AutoSuggestBox.cs +++ b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_AutoSuggestBox.cs @@ -18,6 +18,15 @@ using static Private.Infrastructure.TestServices; using static Microsoft.UI.Xaml.Controls.AutoSuggestionBoxTextChangeReason; +using SamplesApp.UITests; +using Uno.UI.RuntimeTests.Helpers; +using Windows.Foundation; + +#if __IOS__ +using UIKit; +#elif __MACOS__ +using AppKit; +#endif namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls { @@ -25,6 +34,39 @@ namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls [RunsOnUIThread] public class Given_AutoSuggestBox { +#if !WINAPPSDK + [TestMethod] + [UnoWorkItem("https://github.com/unoplatform/uno/issues/15662")] + public async Task When_SymbolIcon_Verify_Size() + { + var SUT = new AutoSuggestBox() + { + QueryIcon = new SymbolIcon(Symbol.Home), + }; + + await UITestHelper.Load(SUT); + +#if __SKIA__ || __WASM__ + var tb = SUT.FindChildren().Single(tb => tb.Text.Length == 1 && tb.Text[0] == (char)Symbol.Home); +#else + var tb = (TextBlock)SUT.EnumerateAllChildren().SingleOrDefault(c => c is TextBlock textBlock && textBlock.Text.Length == 1 && textBlock.Text[0] == (char)Symbol.Home); +#endif + + Assert.AreEqual(12, tb.FontSize); + + var tbBounds = tb.GetAbsoluteBounds(); + +#if __WASM__ + Assert.AreEqual(new Size(13, 12), new Size(tbBounds.Width, tbBounds.Height)); +#elif __ANDROID__ + Assert.AreEqual(new Size(12, 14), new Size(tbBounds.Width, tbBounds.Height)); +#else + // 12, 12 is the right behavior here. + Assert.AreEqual(new Size(12, 12), new Size(tbBounds.Width, tbBounds.Height)); +#endif + } +#endif + #if !WINAPPSDK // GetTemplateChild is protected in UWP while public in Uno. [TestMethod] public async Task When_Text_Changed_Should_Reflect_In_DataTemplate_TextBox() diff --git a/src/Uno.UI/UI/Xaml/Controls/AutoSuggestBox/AutoSuggestBox.cs b/src/Uno.UI/UI/Xaml/Controls/AutoSuggestBox/AutoSuggestBox.cs index 7863d7543c77..729ec22ac26a 100644 --- a/src/Uno.UI/UI/Xaml/Controls/AutoSuggestBox/AutoSuggestBox.cs +++ b/src/Uno.UI/UI/Xaml/Controls/AutoSuggestBox/AutoSuggestBox.cs @@ -349,8 +349,13 @@ private void UpdateQueryButton() return; } - _queryButton.Content = QueryIcon; - _queryButton.Visibility = QueryIcon == null ? Visibility.Collapsed : Visibility.Visible; + var queryIcon = QueryIcon; + if (queryIcon is SymbolIcon symbolIcon) + { + symbolIcon.SetFontSize(0); + } + _queryButton.Content = queryIcon; + _queryButton.Visibility = queryIcon == null ? Visibility.Collapsed : Visibility.Visible; } private void UpdateTextBox() diff --git a/src/Uno.UI/UI/Xaml/Controls/Icons/SymbolIcon.cs b/src/Uno.UI/UI/Xaml/Controls/Icons/SymbolIcon.cs index 71c0cb1d1c68..d0f3fe60ebe8 100644 --- a/src/Uno.UI/UI/Xaml/Controls/Icons/SymbolIcon.cs +++ b/src/Uno.UI/UI/Xaml/Controls/Icons/SymbolIcon.cs @@ -12,7 +12,7 @@ namespace Microsoft.UI.Xaml.Controls; /// public sealed partial class SymbolIcon : IconElement { - private const double DefaultFontSize = 20.0; + private double _fontSize = 20.0; private readonly TextBlock _textBlock; @@ -63,7 +63,12 @@ private void SynchronizeProperties() _textBlock.TextAlignment = Microsoft.UI.Xaml.TextAlignment.Center; _textBlock.HorizontalAlignment = HorizontalAlignment.Stretch; _textBlock.VerticalAlignment = VerticalAlignment.Center; - _textBlock.FontSize = DefaultFontSize; + + if (_fontSize > 0) + { + _textBlock.FontSize = _fontSize; + } + _textBlock.FontStyle = FontStyle.Normal; _textBlock.FontFamily = GetSymbolFontFamily(); _textBlock.IsTextScaleFactorEnabled = false; @@ -73,6 +78,17 @@ private void SynchronizeProperties() _textBlock.Foreground = Foreground; } + internal void SetFontSize(double fontSize) + { + _fontSize = fontSize; + if (fontSize == 0) + { + _textBlock.ClearValue(TextBlock.FontSizeProperty); + } + + InvalidateMeasure(); + } + private void SetSymbolText() => _textBlock.Text = new string((char)Symbol, 1); private static FontFamily GetSymbolFontFamily() =>